Most efficient way to do language file in PHP?

前端 未结 9 1877
日久生厌
日久生厌 2020-12-04 14:39

Questions Updated instead of making a new question...

I really want to provide a few alternative languages other then English on my social network s

相关标签:
9条回答
  • 2020-12-04 15:28

    Don't reinvent the wheel. Use for example gettext or Zend_Translate.

    0 讨论(0)
  • 2020-12-04 15:29

    Don't write your own language framework. Use gettext. PHP has standard bindings that you can install.

    0 讨论(0)
  • 2020-12-04 15:31

    As the other answers don't really answer all the questions, I will go for that in my answer plus offering a sensible alternative.

    1) I18n is short for Internationalization and has some similarities to I-eighteen-n.

    2) In my honest opinion gettext is a waste of time.

    3) Your approach looks good. What you should look for are language variables. The WoltLab Community Framework 2.0 implements a two-way language system. For once there are language variables that are saved in database and inside a template one only uses the name of the variable which will then be replaced with the content of the variable in the current language (if available). The second part of the system provides a way to save user generated content in multiple languages (input in multiple languages required).

    Basically you have the interface text that is defined by the developer and the content that is defined by the user. The multilingual text of the content is saved in language variables and the name of the language variable is then used as value for the text field in the specific content table (as single-language contents are also possible).

    The structure of the WCF is sadly in a way that reusing code outside of the framework is very difficult but you can use it as inspiration. The scope of the system depends solely on what you want to achieve with your site. If it is going to be big than you should definitely take a look at the WCF system. If it's small a few dedicated language files (de.php, en.php, etc), from which the correct one for the current language is included, will do.

    0 讨论(0)
提交回复
热议问题