What is the best(recommended): Create a lang file or store the strings in a database? [closed]

StackOverflow https://stackoverflow.com/questions/21090068

  •  27-09-2022
  •  | 
  •  

質問

I'm trying to do a multi language site, so I want to know what is the best way to store the strings(text). For now, I am using a file like (lang_en.php) that contains an array with the key and the string ($lang['MENU_SEARCH'] = 'This is going to show up there'). Is this the best way to do this? Using a database is better?

役に立ちましたか?

解決

"Best" clearly depends on the situation.

Benefits of using a text file:

  • Easier, quicker development.
  • No database hits.
  • Can be stored and managed through source code control system.
  • Text changes can go through standard QA process.
  • Common solution in other il8n frameworks.

Drawbacks of using a text file:

  • The strings basically become a "software artifact" - only developers can change them, and a simple change requires a software release.
  • Hard to apply formatting to the text, no WYSIWYG.

Benefits of using a database:

  • Changes can be done through admin interface, so no technical skills required, and no software release.

Drawbacks of database:

  • Moderate amount of effort to build simple version.
  • Significant amount of work to build sophisticated version (versioning, test/preview mode); rapidly approaches build of Content Management System in scope.
  • Can introduce performance hit if you don't get the caching right.

他のヒント

Database is always better option considering the scalability. On top of database you can have redis like caching mechanism which allows search too in memory.

Up to best of my knowledge and exposure. Best thing is to create php files and define constants for each interface and include them where required. I personally don't recommend the database approach as it will increase the database trips

a hint for cart.php file as

/languages/en/cart.php

where the syntax of file is something like

define('Title', 'My Shopping Cart');

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top