TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How have you done internationalization (i18n)?

5 点作者 dpods大约 7 年前
We've got a i18n project coming up at my day job. I'm curious to hear other's experiences with completing i18n projects. What worked well, what didn't work so well, what would you do differently? Were there any 3rd party tools or services you used?

3 条评论

bjourne大约 7 年前
It is really, really hard to do i18n really well. Most developers think it is easy because they don&#x27;t consider all the little details that you need to get right. It&#x27;s everything from input fields using comma or period as the decimal separator, Sunday or Monday as the start of the week, to currencies, different line lengths, time formats and much more.<p>IMHO, unless you plan to support more than half a dozen locales, it is less work to do one website (or frontend) for each locale than it is to build one website that adapts to multiple locales.<p>Good enough i18n is much easier. Just keep all strings in an associative array: {(&quot;greet&quot;, &quot;en&quot;) : &quot;Hello&quot;, (&quot;greet&quot;, &quot;ru&quot;) : &quot;Здравствуйте!&quot;} then each time a message is to be printed, have a function that looks up the correct translation: i18n_lookup(string_key, language).
ThePhysicist大约 7 年前
I recommend to keep things simple whenever possible. For most of our website projects we use simple dictionaries that we typically store in YAML files, just like this:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;DPKit&#x2F;gdpr-portal&#x2F;blob&#x2F;master&#x2F;src&#x2F;translations.yml" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DPKit&#x2F;gdpr-portal&#x2F;blob&#x2F;master&#x2F;src&#x2F;transla...</a><p>We then have a custom Jinja filter that looks up the translation for a given word, such as<p><pre><code> {{&#x27;summary&#x27;|translate}} </code></pre> In code, we have a simple helper function like this:<p><pre><code> def t(key, lang): return translations[lang].get(key, &#x27;[{} not found]&#x27;.format(key)) </code></pre> In practice we use a slightly more advanced version of this function (<a href="https:&#x2F;&#x2F;github.com&#x2F;adewes&#x2F;beam&#x2F;blob&#x2F;master&#x2F;beam&#x2F;site.py#L91" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;adewes&#x2F;beam&#x2F;blob&#x2F;master&#x2F;beam&#x2F;site.py#L91</a>) which allows us to also include formatting parameters to allow things like {{&#x27;contact-us&#x27;|translate(name=&#x27;Max&#x27;,email=&#x27;max@mustermann.de&#x27;)}}.<p>You can also keep date and number formats in the i18n dictionary to internationalize dates. Most internationalization libraries do not provide much more than that and try to be overly clever by e.g. offering automated pluralization etc. but in my experience they often subtly break things.<p>Works quite well for us both on the backend as well as frontend, here&#x27;s an example of a website (also open source at <a href="https:&#x2F;&#x2F;github.com&#x2F;DPKit&#x2F;gdpr-portal" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DPKit&#x2F;gdpr-portal</a>) that uses this method:<p>DE: <a href="https:&#x2F;&#x2F;dsgvo.dpkit.com" rel="nofollow">https:&#x2F;&#x2F;dsgvo.dpkit.com</a> EN: <a href="https:&#x2F;&#x2F;gdpr.dpkit.com" rel="nofollow">https:&#x2F;&#x2F;gdpr.dpkit.com</a><p>(we decided to keep the different language versions on separate subdomains for better usability).<p>Don&#x27;t be afraid to write your own solution for simple problems like that, no need to use 3rd party libraries for everything :)
simonpure大约 7 年前
Google has some great resources including a few open source projects [0]. I don&#x27;t use any of them directly, but they have been a great inspiration to learn from their epxerience.<p>[0] <a href="https:&#x2F;&#x2F;developers.google.com&#x2F;international&#x2F;" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;international&#x2F;</a><p>Disclaimer: I used to work on i18n and i10n for Google as a country specialist back in the days.