A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

Overview

Laravel Speaks Arabic

Latest Version on Packagist MIT Licensed Total Downloads

A light weight laravel package , That facilitates dealing with arabic concepts in Laravel Framework using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

wanna see a code snippet?

@toWords(12078437); 
// اثنا عشر مليون و ثمان و سبعون ألف و أربع مئة و سبع و ثلاثون

installation

1.install via composer

composer require adnane/laravel-speaks-arabic

2.Add the Service provider in the Providers Array in config\app.php as bellow :

'providers' => [ 
    Adnane\Arabic\ArabicServiceProvider::class,
]

How to use

  • Make sure you correctly install & setup the package , import the class Adnane\Arabic\Arabic and call the available methods with therequired paramateres

change method to needed method like Arabic::toWords(643646) or arabic()->toWords(643646)

use Adnane\Arabic\Arabic;
Arabic::method($params)

// or directly by using a helper
arabic()::method($params)

Methods

1.Working with numbers & integers

/**
 * get the arabic words representation of a given int , called also تفقيط 
 * @return string 
*/
Arabic::toWords(int $integer)

/**
 * get the numeric representation of a given string , reverse of previous method 
 * @return int 
*/
Arabic::fromWords(string $str) 

/**
 * get the ordinal form of a given int
 * @return string 
*/
Arabic::toOrdinal(int $int) 

/**
 * rewrite numbers in a containing string to be like ۱٧۳۱۸
 * @return string 
*/
Arabic::toIndianNums(string $str) 

2.Working with dates & times

/**
 * convert a given date to hijri takwim date in a given format (format : f , s , n )
 * @return string 
*/
Arabic::toHijri(string $format = 'f' ,string $date)

/**
 * convert a given hijri hijri to gregorian normal date 
 * @return string 
*/
Arabic::fromHijri(string $date /*Y/m/d*/);

/**
 * Get the relative time between two given dates 
 * @return string 
*/
Arabic::toRelative(string $date ,string $date2 = null ,boolean $detailed = false);

/**
 * Get the date from a given relative time 
 * @return string 
*/
Arabic::fromRelative(string $relative);

3.Working with Strings & longTexts

/**
 * get rid of The vowel diacritics in Arabic  
 * @return string 
*/
Arabic::removeHarakat(string $str)

/**
 * rewrite strings and texts to match the keyboard reveresed in english 
 * this method can be really helpful when it comes to making search procces better 
 * @return string 
*/
Arabic::toKeyboardInput(string $str)

/**
 * rewrite strings and texts to be written and spelled in english letters 
 * this mehotd can be really helpful when it comes to making seo friendly url's or arabic slugs 
 * @return string 
*/
Arabic::toSpelled(string $str)

/**
 * equivilant of str_word_count in non utf8 strings & longTexts such as arabic  
 * @return int 
*/
Arabic::countWords(string $str);

/**
 * check if a given string contains arabic charachters 
 * @return boolean 
*/
Arabic::containsAr(string $str);

Examples Of Different Uses

3 , "m" => 39 ,"w" => 156 , "d" => 1096 ,"h" => 26304 ,"mn" => 1578240 ,"s" => 94694400 ] Arabic::fromRelative('زد سنة') // 2022/03/28 Arabic::fromRelative('قل ست اشهر') // 2020/09/28 Arabic::removeHarakat('لا حسَدَ إلَّا في اثنتيْنِ: رجلٌ آتاهُ اللهُ مالًا، فسلَّطَهُ على هلَكتِه في الحقِّ، ورجلٌ آتاهُ اللهُ الحِكمةَ، فهوَ يقضِي بِها، ويُعلِّمُها') // لا حسد إلا في اثنتين: رجل آتاه الله مالا، فسلطه على هلكته في الحق، ورجل آتاه الله الحكمة، فهو يقضي بها، ويعلمها Arabic::toKeyboardInput('dl;k hsjulhg ihji hg]hgm td jpsdk ulgdhj hgfpe fl,ru!') // يمكن استعمال هاته الدالة في تحسين عمليات البحث بموقع! Arabic::toSpelled("قد تساعد هاته الدالة في عمل slugs أو تحسين عمليات البحث") // qd tsaaad haath āldaalt fii aml slugs āoo thsiin amliiāt ālbhth Arabic::countWords("هاته الدالة هي المكافئة لاخرى بالبي اتش بي غير ان هاته لا تتجاهل ترميز اليو تي اف ايت") // 18 Arabic::containsAr("this method checks if a given string contains arabic words or charachters , for example : if we mentioned لارفيل يتحدث عربي it will return true!") // true ">
Arabic::toWords(56)
//  ست وخمسون

Arabic::fromWords("ثمان مئة و خمسة")
//  805

Arabic::toOrdinal(12)
//  الثاني عشر

Arabic::toIndianNums("ولد عليه الصلاة في 12 ربيع الأول")
//  ولد عليه الصلاة في ۱۲ ربيع الاول

Arabic::toHijri('f' ,'2021/12/12')
//  الثامن من جمادى الأولى من السنة الهجرية ألف و أربع مئة و ثلاث و أربعون

Arabic::fromHijri('1442/01/08')
// 8/27/2020

Arabic::toRelative('2010/01/10')
//  منذ أحد عشر سنة

Arabic::toRelative('2010/01/10' ,'2008/01/10')
//  ثلاث سنين 

Arabic::toRelative('2010/01/10' ,'2008/01/10' ,true)
// [ "y" => 3 , "m" => 39 ,"w" => 156 , "d" => 1096 ,"h" => 26304 ,"mn" => 1578240 ,"s" => 94694400 ] 

Arabic::fromRelative('زد سنة')
// 2022/03/28

Arabic::fromRelative('قل ست اشهر')
//  2020/09/28

Arabic::removeHarakat('لا حسَدَ إلَّا في اثنتيْنِ: رجلٌ آتاهُ اللهُ مالًا، فسلَّطَهُ على هلَكتِه في الحقِّ، ورجلٌ آتاهُ اللهُ الحِكمةَ، فهوَ يقضِي بِها، ويُعلِّمُها')
//  لا حسد إلا في اثنتين: رجل آتاه الله مالا، فسلطه على هلكته في الحق، ورجل آتاه الله الحكمة، فهو يقضي بها، ويعلمها

Arabic::toKeyboardInput('dl;k hsjulhg ihji hg]hgm td jpsdk ulgdhj hgfpe fl,ru!')
// يمكن استعمال هاته الدالة في تحسين عمليات البحث بموقع!

Arabic::toSpelled("قد تساعد هاته الدالة في عمل slugs أو تحسين عمليات البحث")
// qd tsaaad haath āldaalt fii aml slugs āoo thsiin amliiāt ālbhth

Arabic::countWords("هاته الدالة هي المكافئة لاخرى بالبي اتش بي غير ان هاته لا تتجاهل ترميز اليو تي اف ايت")
// 18

Arabic::containsAr("this method checks if a given string contains arabic words or charachters , for example : if we mentioned لارفيل يتحدث عربي it will return true!") 
// true

use in blade files

change method to needed method like Arabic::toWords(643646) or arabic()->toWords(643646)

{{ Arabic::method($input) }}

or

{{ arabic()->method($input) }}

as you can use the following blade directives for clean coding :

@toWords(4367)
@toOrdinal(564)
@toIndianNums(ولد عليه الصلاة في 12 ربيع الأول) 
@toHijri(2020/12/12)
@toRelative(2019/12/01)
@removeHarakat(فهوَ يقضِي بِها، ويُعلِّمُها)

Important Notes

Please feel free to contribute or help us making laravel speaks arabic better by opening a discuss ,Adding some extra methods , fixing a bug or helping in improving some methods!

How to Contribute

it's highly recommended you follow the written code manner

  1. Create new PHP class in /src/Ar/
  2. You may need to add some data in /Ar/data/YourFolder/
  3. define your method & related instance in $methods property in /src/Arabic.php !

That's it!

You might also like...
A Laravel response helper methods.
A Laravel response helper methods.

A Laravel response helper methods. The package respond provides a fluent syntax to form array or json responses.

Source code behind the Laracasts Larabit: My Favorite Laravel Collections Methods

My Favorite Laravel Collections Methods This is the source code behind the Laracasts Larabit: My Favorite Laravel Collections Methods, and features al

A laravel package to attach uuid to model classes

Laravel Model UUID A simple package to generate model uuid for laravel models Installation Require the package using composer: composer require touhid

🏭This package lets you create factory classes for your Laravel project.
🏭This package lets you create factory classes for your Laravel project.

Laravel Factories Reloaded 🏭 This package generates class-based model factories, which you can use instead of the ones provided by Laravel. Laravel 8

Learn how to accept a payment from customers around the world with a variety of payment methods.

Accept a payment Learn how to securely accept payments online. This repository includes examples of 2 types of integration types. Prebuilt Checkout pa

A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

PHPColors A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly. Requirements PHPColo

Laravel package for giving admin-created accounts to users via 'set-password' email.

Invytr When making a website where users are created instead of registering themselves, you are faced with the challenge of safely giving users the ac

This Laravel 8 package makes it possible for you to set your website in
This Laravel 8 package makes it possible for you to set your website in "Under Construction" mode.

Laravel Under Construction This Laravel package makes it possible to set your website in "Under Construction" mode. Only users with the correct 4 digi

Make Laravel Pivot Tables using the new Laravel 9 closure migration format

This will allow you to create pivot table migration files using the new Laravel 9 closure migration format by simply passing two models.

Releases(1.0.3)
Owner
Adnane Kadri
Use case driven.
Adnane Kadri
Simple Arabic Laravel Dashboard , has basic settings and a nice layout . to make it easy for you to create fast dashboard

Simple Arabic Laravel Dashboard ✅ Auto Seo ✅ Optimized Notifications With Images ✅ Smart Alerts ✅ Auto Js Validations ✅ Front End Alert ✅ Nice Image V

Peter Tharwat 254 Dec 19, 2022
This package gives you a set of conventions to make the most out of Hotwire in Laravel

Introduction This package gives you a set of conventions to make the most out of Hotwire in Laravel (inspired by the turbo-rails gem). There is a comp

Tony Messias 665 Jan 2, 2023
An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality.

Support An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality. Ins

Ian Olson 3 Apr 14, 2021
Control frontend access to properties/methods in Livewire using PHP 8 attributes.

This package adds PHP 8.0 attribute support to Livewire. In specific, the attributes are used for flagging component properties and methods as frontend-accessible.

ARCHTECH 83 Dec 17, 2022
This package provides convenient methods for making token code, sending and verifying mobile phone verification requests.

Laravel Mobile Verification Introduction Many web applications require users to verify their mobile phone numbers before using the application. Rather

M.Fouladgar 347 Dec 25, 2022
A package that helps to group methods that mostly use for the view presentation purpose.

A package that helps to group methods that mostly use for the view presentation purpose form models to a dedicated presenter class.

Touhidur Rahman 9 Apr 26, 2022
A thin and light scaffolded Laravel Dusk environment.

Laravel Husk Larvel Husk is a thin and light scaffolded Laravel Dusk environment. It allows you to test your JavaScript applications with PHP using Pe

Steve Bauman 85 Dec 26, 2022
Package with small support traits and classes for the Laravel Eloquent models

Contains a set of traits for the eloquent model. In future can contain more set of classes/traits for the eloquent database.

Martin Kluska 3 Feb 10, 2022
These are simple array and object collections that provide convinient methods to manipulate them.

Simple Collections These are simple array and object collections that provide convinient methods to manipulate collections; To install this package ty

Artem 4 Nov 19, 2021
Quickly identify controller methods with no route in your Laravel applications.

Orphan Controller Quickly identify controller methods with no route in your Laravel applications. Installation You can install the package via Compose

Ryan Chandler 16 Feb 18, 2022