Giter Site home page Giter Site logo

mdaliyan / farsi-request Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 2.0 51 KB

farsi request replaces arabic characters like ي ك ة ٤ ٥ ٦ with farsi characters in all your requests parameters automatically.

License: MIT License

PHP 100.00%
farsi-characters farsi farsi-request request persian persian-number arabic-numbers

farsi-request's Introduction

Farsi Request

Build Status License

Farsi Request replaces arabic characters like ي ك ة ٤ ٥ ٦ with Farsi characters like ی ک ه ۴ ۵ ۶ in all your requests parameters automatically.

If you are building a farsi website you might end up having some users who use Arabic keyboard. These users may cause problems to your content or experience some confusion while searching among your content.

Tested

farsi-request is tested on laravel 5.x && 6.x

Features

  1. Replaces Arabic characters with farsi standard characters

  2. Automatically Converts Farsi or English Numbers to each other in your desired request parameters to one another. For example:

    • Product names, like R2D2 should never have farsi numbers, right?
    • user's phone number

Install

$ composer require mdaliyan/farsi-request

Usage

1. Auto-Replace arabic characters

Add this middleware to your kernel file app/Http/Kernel.php

protected $middleware = [
    ...
   \Mdaliyan\FarsiRequest\Middleware\ReplaceArabicCharacters::class,
];

2. Auto-Replace numbers in request parameters

Add this trait and two private properties to your Request Class. Then add the parameters that should have farsi or english numbers to the desired property.

use Mdaliyan\FarsiRequest\Traits\ReplaceNumbers;

class SomeRequest extends FormRequest
{
    use ReplaceNumbers;

    private $mustHaveEnglishNumbers = ['id','email','phone_number'];
    private $mustHaveFarsiNumbers = ['post_content','author_name'];

    /**
     * Determine if the user is authorized to make this request.
     * @return bool
     */
    public function authorize()
    {
        return true;
    }
    ...

Note: this feature ignores numbers inside HTML tags:

    This line with the numbers 889 and an image: <img src="/media/media2.jpg">
    
     <!-- will be converted to: -->
    
    This line with the numbers ۸۸۹ and an image: <img src="/media/media2.jpg">

farsi-request's People

Contributors

anisi avatar mdaliyan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

masoodvahid anisi

farsi-request's Issues

2 errors in ReplaceNumber

Hello
It has 2 problems in ReplaceNumber Trait:

  1. It doesn't support array requests like this:
{
	"firevehicles":[0,1]
}

and throws this exception:

ErrorException: preg_match_all() expects parameter 2 to be string, array given
in /home/mojtaba/WebProjects/firebase/vendor/mdaliyan/farsi-request/src/Traits/ReplaceNumbers.php:51
  1. It tries to replace numbers before validation and if an required request attribute was empty, it throws an exception:
ErrorException: count(): Parameter must be an array or an object that implements Countable
in /home/mojtaba/WebProjects/firebase/vendor/mdaliyan/farsi-request/src/Traits/ReplaceNumbers.php:74

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.