在同一语言环境中进行本地化?

Localisation in the same locale?

根据使用上下文,我需要“翻译”相同语言环境中的一些词。

一个例子:

使用 cakephp 3 的本地化功能最好的方法是什么?

我可以使用 :I18n::setLocale('context1'); ?

谢谢

不要根据上下文更改区域设置。语言环境总是指当前的翻译。上下文是语言问题。

来自手册:

Sometimes translations strings can be ambiguous for people translating them. This can happen if two strings are identical but refer to different things. For example, ‘letter’ has multiple meanings in English. To solve that problem, you can use the __x() function:

所以你会写:

 echo __x('as team', 'team');
 echo __x('as group', 'team');
 echo __x('as troop', 'team');

CakePHP 将向翻译文件写入一条消息以指示上下文是什么。

https://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#using-translation-functions