Structuring Website Translation files

前端 未结 3 1675
鱼传尺愫
鱼传尺愫 2021-02-08 14:41

I faced this problem several times while building websites. I will explain the using PHP and Laravel as an example but this problem is a common amoung multiple platforms. This w

3条回答
  •  日久生厌
    2021-02-08 15:20

    I would go with option #4, so you'd have something like this:

    /lang/
        /en 
          messages.php
          words.php
        /fr
          message.php
          words.php
        /de
          messages.php
          words.php
    

    This does a few things:

    • It segments out everything very clearly. You know which language to find where. And you know what's in the file associated with the language.
    • The above makes maintenance easier in the future because you can find stuff.
    • It gives you files, by language, that can be translated separately.
    • It puts all the message in one clearly defined place.

    One thing to note, is that if your app gets REALLY big and REALLY international, you may want to use ISO language codes instead. For example, european Portugese (pt_PT) and Brazilian Portugese are different and with a global audience you'd probably want to cover both.

提交回复
热议问题