Home >Backend Development >PHP Tutorial >Discuss YII2 development of multi-language dynamic website solutions
In addition to using multiple sets of data table solutions, are there any other solutions? It is necessary to ensure that all data read from the database is multi-lingual.
In addition to using multiple sets of data table solutions, are there any other solutions? It is necessary to ensure that all data read from the database is multi-lingual.
It is too rare to use multiple sets of data tables. Generally, language files are used...The database can only store keys, and then automatically convert them into translation keywords, such as category tables
category.id = 1, category.name = ' Demo', category.slug = demo, category.meta = 'It is demo'
Corresponding translation file
category_id_1_name = 'Demo'
category_id_1_meta = 'This is a demo'
If necessary, you can develop your own language file management page , but generally an editor similar to PO will suffice.
Of course, some things cannot be processed in this way, such as documents, which require additional language fields instead of creating new tables. For example, the article table will contain id, language, title, content, etc. When displaying, it will automatically filter out different document lists based on language.
To summarize, simple translation uses language files, complex data adds language fields, and content in different languages is managed as multiple records.
As for "all data read from the database are multi-lingual", this solution is too tiring, the database is under great pressure, the amount of data maintenance is also large, and it lacks flexibility. Usually we think that translation is a solution used by the front end to optimize interaction, rather than the work of the database. Similar problems include currency conversion, number format, and date format. Do you have to rely on a database? Create a new product and save prices in 3 different formats? I feel tired just thinking about it.