4

I decided to try to translate my rails app using i18n into Arabic language which right to left , unlike English language ( from left to right ) , how can I reverse my website in case of Arabic , and reset it back in case of choosing English ?

I tried <html dir="rtl"> , it only changes the direction of the text , I need to make something like in facebook its change the whole site according to the selected language if its from R to L or L to R

How to make a condition to change between RTL and LTR in rails application ?

Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61
  • 2
    Have you seen this? http://www.w3.org/TR/i18n-html-tech-bidi/ – Brad Werth May 08 '13 at 06:19
  • It's not for rails ! i cant use it in a rails app to change between LTR and RTL , or if you have a solution just you can write and explain it please. – Mostafa Hussein May 08 '13 at 13:02
  • Perhaps something like localizing the CSS file? http://stackoverflow.com/questions/9310044/rails-i18n-of-css-file – olleolleolle May 08 '13 at 13:05
  • 1
    Believe it or not, Rails uses HTML... – Brad Werth May 08 '13 at 13:28
  • and believe it or not , in Fedena rails application [Educational ERP SYSTEM] they have RTL support and the wrote in a condition by ruby on rails between <%=> and use css also, which makes you able to use the RTL and LTR , so i need a solution in rails and css , because i dont know what they add in the other files ! – Mostafa Hussein May 08 '13 at 14:25
  • look in (https://github.com/projectfedena/fedena/blob/master/app/views/layouts/application.html.erb) – Mostafa Hussein May 08 '13 at 14:28

1 Answers1

1

As i was searching for a similar problem, i encountered your question. Here is what i do. in views:

<div class="some-css-class-<%= I18n.locale.to_s %>"> some content </div>

and then in your css files you should duplicate some classes.

For example if you had something like this:

.some-css-class{ align: left; }

you should change it to

.some-css-class-en{ align: left; } .some-css-class-ar{ align: right; }

Although i suggest that you define a direction variable in your layout or application_controller.rb or even application_helper.rb that specifies page direction: @direction_page = (I18n.locale==:ar)?("rtl"):("ltr") which is more expandable for future changes.

David
  • 15,894
  • 22
  • 55
  • 66