0

I have my clients requirement that the site needs to be able to support any language that he wants, ie he wants to add languages dynamically from backend. I know we can use messages folder by creating files and calling from respective files but the problem is we'll not know which language he needs.

I am getting very confused with the concept of unlimited languages support. I cant' seem to save all the languages in database either as it would get vague later creating new tables each time and linking it to each contents (or text).

Please help me figure out descriptively or with ER diagram for database structure. Any help will be greatly appreciated.

Thanks

EDIT: Here is the process client wants. (HE means CLient)

I am creating a trekking site where many viewer from different countries will view the site. So he wants to add the languages for those countries. But he is not sure which countries are needed at this moment.

1) He'll create a language eg Germany. 
2) Goes to add a tour or trekk.
3) Select the language he had created (Germany and others)
4) If the required language is not there he'll go back to language and create it and return to add a tour/trek

Thats it actually. And in frontend users will be able to select the language in dropdown which should obivously give the contents accordingly.

I know the question seems a bit vague. But i have no clue how to get started with this one. What i need is precise database concept. If its still not clear please ask questions so that i could provide more info and could be helpful to other with similar task.

Prajwol Onta
  • 1,448
  • 5
  • 21
  • 48

2 Answers2

1

By the sounds of your requirements, Yii's internationalization should do the trick for you. This is how I would do it:

See the following ERD: ERD database for internationalization

lang_source: will be your table for the source language (default is English and it's not recommended to change it).

lang_translation: will be the table where all your translations will be stored.

NB: note the identifying relationship between the two tables.

Whenever you have content that needs to be translated, use Yii::t() that accepts 2 arguments, namely a category (used to help structure your translatable content) and the content itself (message). Example: <?= Yii::t('myCategory', 'Welcome to my website'); ?>

Yii knows which language to 'fetch' in the database by settings the language 'language'=>'en-US' in your config.

Every record in the lang_translation table corresponds with a lang_source record, that way you can add records in lang_translation for all the translatable content in lang_source for each and any language you would want.

In other words, in the backend you can check if a record exists for a certain language and message. If not, that translation needs to be inserted into lang_translation. That way you don't need to create any tables for new languages.

Hope this helps!

Community
  • 1
  • 1
deacs
  • 4,259
  • 2
  • 27
  • 37
0

May this answer help you. In main.php we specify the language folder by writing 'language' => 'en', for each language we need separate folders and need to write files specific for that language on that folder. In above example 'en' is the folder name. Change the value of 'language' on main.php based on required language. I am sorry if this wasn't the answer you were looking for.

Sajin
  • 141
  • 2