How select locale for inline translations in Magento2? How use in Magento2 inline translations with chosen locale in code?

时间:2017-06-20 12:36:03

标签: php translation magento2

We need to have ability in code use inline translations with translated strings from csv files with selected locale, which is different from store. For example, user select english language in frontend, but we want to create PDF or rend email with de_DE translations. We want to get something like this (not correct this code)

> setLocale('de_DE');
> __('Good morning'); 

// Guten Morgen

1 个答案:

答案 0 :(得分:1)

我找到了解决方案!!!! 我已经尝试了很多代码和建议。但对我来说,解决问题的一种方法是: 所以在Magento \ Framework \ App \ Language \ Dictionary类中存在

function getDictionary($locale) 

从csv文件返回所选语言环境的数组。然后我只是从数组中获取值 - 基本语言中的默认字符串 - 英语。