Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 - Multi Language Website for (LTR and RTL)

Hi to all developers...

I'm new to Laravel. I want to build a complex web application and it's important to support at least 2 language. Unfortunately, One of these language is LTR and other is RTL!
My questions are:

  1. Some parts of website have static content, like headers, navigation items, sidebar content or... . As I understand, I must create files in lang directory and based on selected language, load proper data. Is it right? In this way, Is it possible to load these static data from lang directory files cause slower app and bad performance? (compare with static views, blade files that have content and don't need to load small piece of data from lang directory).
  2. Considering first question, is it better to have one set of views for one language and another set of views for second language? (each set of views have their static data and don't require use lang files to full parts of header, sidebar and...)
  3. As I said, I must have a LTR and a RTL layout in order to have best UI. So I must have separate stylesheets and loads based on choosen language, is it right?

I have some questions for multi language database design, but I start a new discussion later. Thanks for your attention and I hope that you guide me and say your opinions...

like image 380
FS Webeloper Avatar asked Mar 22 '17 10:03

FS Webeloper


1 Answers

Some parts of website have static content, like headers, navigation items, sidebar content or... . As I understand, I must create files in lang directory and based on selected language, load proper data. Is it right? In this way, Is it possible to load these static data from lang directory files cause slower app and bad performance? (compare with static views, blade files that have content and don't need to load small piece of data from lang directory)

  • Yes, by all means make sure you abstract your language from your views. This is a good practice that you will definitely want to do to save yourself multiple identical views per language (nightmare!).
  • When you program anything there is a performance overhead. When you use functionality such as this, you're making your life a lot easier. The performance hit is tiny. Don't use this as a reason to not do this.

Considering first question, is it better to have one set of views for one language and another set of views for second language? (each set of views have their static data and don't require use lang files to full parts of header, sidebar and...)

  • No, this is a nightmare scenario for most developers. Maintaining multiple brittle views due to language eats up time when separation of these concerns at the beginning removes any need for this to happen.

As I said, I must have a LTR and a RTL layout in order to have best UI. So I must have separate stylesheets and loads based on choosen language, is it right?

  • LTR and RTL is a problem wholly solvable using some simple CSS alone, no need to have separate style sheets. Instead, using a single class on the body you can apply the correct styling. <body class="{{ $rtl ? 'rtl' : 'ltr'}}">. Now you can use CSS' direction property to define the direction text reads.

As you are using Laravel, leverage the framework as much as you can. There is no need for you to re-invent the wheel with this.

like image 127
David Barker Avatar answered Sep 30 '22 03:09

David Barker