Structuring Website Translation files

前端 未结 3 1681
鱼传尺愫
鱼传尺愫 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

    In my experience there is no reason to have different groups other than trying to use your translations somewhere else. I usually put all my project messages in a group named app and for each of my shared libraries I use a separate group name (because I might use them in other projects). An example of a a failure login message in my website would be

    trans('app.username_and_password_do_not_match')
    

    and if it's in a third party library named Auth it would be

    trans('auth.username_and_password_do_not_match')
    

    And remember to write the full message as your message key instead of using short names (like app.login.fail). this way you don't need to check the website content for every translation.

    I didn't fully understand your last problem so you might want to clarify it a bit.

提交回复
热议问题