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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

BabelBox – Minimal internationalization library

17 点作者 yasserf超过 9 年前

3 条评论

jimrandomh超过 9 年前
Whenever I look at modern internationalization libraries and compare them to GNU gettext, I feel like a key piece of knowledge got lost somewhere. BabelBox continues the trend of apparently not having ever used gettext or understanding how it should work. Here&#x27;s how it works in gettext. Let&#x27;s say you have something that prints a message:<p><pre><code> print(&quot;Hello, world.&quot;); </code></pre> If a string should be translated, you wrap it in a call to gettext:<p><pre><code> print(gettext(&quot;Hello, world.&quot;)); </code></pre> In a webapp, you&#x27;d need an extra parameter for the session or locale, but the principle is the same. Note that the parameter was the initial english text. This is the first way i18n libraries go wrong: they make the parameter a key, instead of the english message.<p><pre><code> print(i18lib(&quot;hello_msg&quot;)); </code></pre> This makes the code less readable, and forces you to update a second location to add the English version. It also means you can no longer search the code for an english-language string and get to the right line.<p>I guess forcing the developer to update that second location is the reason for doing it that way, but gettext does something better: you run a tool on your source code which automatically detects calls to the gettext function, and produces a file with all the strings, ready to hand off to translators. This is ridiculously much more programmer-friendly.<p>Templating adds a bunch of complexity to this, and languages have weird quirks that sometimes need to be handled with code. But it&#x27;s sad that the basics got forgotten.
评论 #10589850 未加载
评论 #10589671 未加载
评论 #10589143 未加载
TN1ck超过 9 年前
It&#x27;s really basic, the last time I needed this level of translation-capabilities, I wrote it myself.<p>Currently I can recommend <a href="http:&#x2F;&#x2F;formatjs.io&#x2F;" rel="nofollow">http:&#x2F;&#x2F;formatjs.io&#x2F;</a>. We use it with the react-wrapper and it works really good. It handles everything from ICU-capabilites to formatting dates&#x2F;currencies.
评论 #10589083 未加载
unwind超过 9 年前
I know it&#x27;s in the URL, but I really think the title should mention &quot;JavaScript&quot; just to make it a good free-standing title.
评论 #10588649 未加载