Search code examples
phpdatabaselang

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


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?


Solution

  • "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.