symfony 中的 I18n 具有部分翻译和多种首选语言

发布于 2024-11-05 11:44:45 字数 331 浏览 0 评论 0原文

我正在开发一个网站来培训学生参加编程竞赛。目前该网站主要是法语,但将被翻译成西班牙语(另一个国家希望使用我们的培训网站)。

界面的国际化很容易,但 1500 多个练习在很长一段时间内不会全部翻译。

我需要的是一种以用户选择的语言本地化内容(和界面)的方法,但如果该特定翻译在该语言中不可用,那么应该使用默认翻译(法语)。 我们甚至想概括一下:想象一些法语练习被翻译成英语,你是一个西班牙人并且不会说法语。您首先需要西班牙语版本,然后是英语版本,然后是法语版本。

在这种情况下有没有使用国际化的好方法?

我可以尝试一种语言,如果没有任何结果,请尝试另一种语言,但效率不会很高......

I'm developping a website to train students for programming contest. Right now the website is mostly in french but it's going to be translated in spanish (one other country wants to use our training website).

Internationalisation of the interface is easy but the 1500+ exercices will not all be translated before a long time.

What I need is a way to localize the content (and the interface) in the language choosen by the users but if that specific translation is not available in that language then one should use the default one (french).
We would even want to generalize that : imagine that some french exercises are translated in english, your are a spanish person and don't speak french. You first want the spanish version, then the english one and then the french one.

Is there a good way to use internationalization in this case ?

I can try one language and if there isn't any result try an other one but it wouldn't be very efficient....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2024-11-12 11:44:45

对于模板内容,如果您使用 Symfony i18n 行为,后备默认语言将自动可用。如果找不到翻译的字符串,无论您在 __('string') 帮助程序中放入什么内容,都将使用默认区域性(在 settings.yml 中声明)。对于多语言数据库内容,您需要使用 Symfony i18n 表行为或自己构建它。如果找不到特定语言的内容,我不知道 Symfony i18n 数据库处理在默认语言的情况下如何工作。查询可能会变得复杂。我的一般意见是,您最好自己构建与数据库相关的功能,但这只是我的看法。

对于排序语言(首先是翻译,然后是英语,然后是默认),我的理解是开箱即用的 Symfony i18n 行为不支持这一点。您可以通过确保在西班牙语 XML/XLIFF 文件中将英语翻译放入可提供英语(但不是西班牙语)翻译的 标记内来破解某种类型的解决方案。这将为您提供 ES -> CN -> FR。但是,我还建议您致力于干净地“管理”您的翻译,以免变得过于复杂/混乱。

希望有帮助。

For template content, if you're using the Symfony i18n behaviour, the fall-back default language will be automatically available. Whatever you put inside the the __('string') helper will use the default culture (declared in settings.yml) if a translated string is not found. For multi-language database content, you'll either need to use the Symfony i18n table behaviour or build this yourself. I don't know how the Symfony i18n database handling works in the case of a default language if content in a specific language is not found. The queries can get complex. My general opinion is that you'll be better off building the database-related functionality yourself, but that's just me.

For ordering the the languages (first translations, then English, then default), my understanding is that the out-of-the-box Symfony i18n behaviour does NOT support this. You might be able to hack some type of solution by ensuring that in your Spanish XML/XLIFF file, you put English translations inside the <target> tags where the English (but not Spanish) translations are available. This will give you ES -> EN -> FR. However, I would also recommend that you aim to "manage" your translations cleanly so that it doesn't become too complicated/confusing.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文