Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting a multilingual site in Laravel

I'm about to create a multilingual site where English will be used for the public pages then Arabic for the Admin. I've never worked on this before and am unsure where to begin. Maybe those who've done multilingual sites before can answer a few questions for me.

  1. Can English and Arabic be saved in the same table? If so, my collation has always been utf-8 Unicode, does that mean I can't use utf8 anymore?
  2. Will the Arabic portions of my site need its own table? If so, what collation?
  3. In my Views, what do I type in replacement for <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />?
  4. Is there anything I should know about starting a multilingual site?

Thanks in advance! I really am a bit lost on where to begin on this.

like image 606
enchance Avatar asked Apr 22 '13 12:04

enchance


1 Answers

  1. Yes, you can use utf8
  2. No, you can use both Arabic and English in the same table
  3. The Arabic charset is iso-8859-6, so you'll need to change the charset attribute in the admin views
  4. You probably want to use body { direction: rtl; } in your css for the Arabic pages

You might find these links useful:

  • Laravel localization docs
  • Finding the current language in a Laravel view
  • Switching languages

When you want to validate form fields using Laravel's translation files (application/language/XX/validation.php), you will find that the :attribute placeholder uses the form field's name attribute, resulting in a mostly-translated error message with the word "email" (or whatever) in English. You can work around this by using the Validation Attributes array to hook up the English field names with the Arabic equivalent. If you find you've already translated them in another language file, you can use the following code instead:

'attributes' => array_merge(
    Lang::file('application', 'ar', 'filename_without_extension'),
    Lang::file('application', 'ar', 'another_file')
),
like image 88
BenjaminRH Avatar answered Oct 14 '22 18:10

BenjaminRH