ArabicHelper Plugin

After working on several Ruby on Rails projects in Arabic lately I ended up repeating some functionality to support Arabic localization, specially on the Model and View levels so I decided to create a plugin for that, and I called it ArabicHelper.

I’ve been also following the updates in rails-I18n and did some work on the Arabic locale file, you can find it here. You can simply use it if you are on Rails 2.2 or Rails Edge, or if you are not then use ArabicHelper.

ArabicHelper

A plugin to help you localize your Rails app to Arabic, this include few useful helpers and ActiveRecord localization

Arabic Helper consists of two parts, model extension and views helper methods. Model extension is to help you have Arabic error messages and attributes names in your model. Helper methods are made to support, pluralizing, country names and time distance in Arabic.

Example

Model extension:

  class Post
    has_arabic_attributes :body    => 'النص',
                          :user_id => 'الكاتب'
  end

View/Controller

  @post = Post.first
  @post.arabic_full_messages

Available helpers:

  arabic_country_options_for_select
  arabic_time_ago_in_words(from_time, include_seconds = false)
  arabic_distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
  arabic_pluralize(number, singular, double, plural, gender_class='male')

Install the plugin:

./script/plugin install git://github.com/rbarazi/arabic_helper.git

Comments

11

  1. Moski Doski said..

    Really cool idea, will give it a shot today and see how it goes.
    Thanx

  2. waseem said..

    Excellent work and you I recommend you to change PHP

  3. waseem said..

    Would not need to reinvent the wheel again

  4. dotone said..

    Yo, remember the dot1_ol? It’d be a great combo if the OL tags get arabized on the fly using JS using your plug-in. That way, even when the header sent is en-US or whatever, on Arabic pages OL tags show arabic numbers/formats. If you’re positive on this I can rework out the experimental JS-Class and turn it into a production version. Here’s the dot1_ol

  5. Rida said..

    @Moski Doski: Thanks, please let me know of any suggestions you may have.

    @waseem: I’m sorry but I didn’t really get what you mean :)

    @dotone: Sure man, I looked into it yesterday, it would be great if you can work on a production version. I’ll added it once it’s ready.. That would be really cool :D

  6. shuaib said..

    Dear Rida, Thanks for the great work. I am using this plugin now and it is helpful.

    I am wondering about some implementations.

    when I want to validate the fields of the form, I use error_messages_for. which will use the default rails error message output. How can we use arabic_full_messages to do the same. I made that manually
    http://pastie.org/295596
    to give me the proper output. Am I missing the way or something in the plugin or you still did not implement that.

    Thanks

  7. shuaib said..

    Well, i needed to use your plugin

    you may click add the ad to see the error message I mean.
    http://www.shobiddak.com/stuffs/new

    I implemented it like this
    http://pastie.org/295603

    I noticed that when I use
    validates presence of, the output will be in arabic but the column name is not arabized??

  8. Rida said..

    @shuaib I’m glad you found the plugin useful, I’ll soon add support for error_messages_for and will post the update here.

  9. Rida Al Barazi » Blog Archive » Testing your Rails plugin said..

    [...] I first released both ArabicHelper and SimplySearchable I didn’t have any tests for them because I didn’t know the right [...]

  10. Testing your Rails plugin - interactiveME said..

    [...] I first released both ArabicHelper and SimplySearchable I didn’t have any tests for them because I didn’t know the right [...]

  11. Testing your Rails plugin - interactiveME said..

    [...] I first released both ArabicHelper and SimplySearchable I didn’t have any tests for them because I didn’t know the right [...]

Leave a Reply

you can use these xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Articles Permanent Link