【问题标题】:Effective way to structure translations in RoR?在 RoR 中构建翻译的有效方法?
【发布时间】:2012-07-03 16:24:52
【问题描述】:

我希望有人能看一下这个,因为我以前除了英语外从来没有翻译过任何东西,所以我不确定是否会有语法冲突。

我有:

en:
  articles:
    name: "Articles"

  comments:
    name: "Comments"

  # things
  no_results: "There are no %{things}"
  my: "My %{things}"

然后在一个视图文件中,例如:

#title= t('articles.name')

%ul
  %li= link_to t('my', things: t('articles.name')), articles_path(user)

.no_results= t('no_results', things: t('comments.name').downcase)

我想要做的是干掉我的翻译,但也不会让使用方法一团糟:

  • 复数
  • 单一化
  • 小写
  • 大写

在文本中使用的模型最常见的形式似乎是大写和复数形式,这就是我选择“Articles”与“Article”或“article”的原因。您是否更喜欢查看文件中的上述方法而不是类似的方法:

articles:
  one: "Article"
  other: "Articles"

..这可能会发展成这个烂摊子:

articles:
  one:     "Article"
  other:   "Articles"
  one_l:   "article"
  other_l: "articles"

【问题讨论】:

    标签: ruby-on-rails internationalization


    【解决方案1】:

    不同的语言对于如何构建句子有不同的规则。干掉你的翻译可能会导致在外语中出现语法错误的句子。我建议一次坚持一个逻辑文本块。例如段落、句子、表达或单词。

    例如,您假设在您希望将您的应用程序翻译成的每种语言中,“my”一词始终位于“articles”一词之前,并且“my”只有一个词。

    在某些语言中,“my”的版本可能取决于与之相伴的单词。我会使用保加利亚语,因为我很熟悉——“我的车”翻译成“Moiata kola”,“我的卡车”翻译成“Moiat kamion”。不是“我的”的直接翻译。

    另外,在某些语言中,您可能不得不说“我的文章”之类的内容,其中“文章”位于“我的”之前。对于不同的语言,您可以将“articles”配置在“my”之前,但如果您的翻译包含多个变量,则可能会出现问题。

    我会为每个单独的行:“我的文章”、“没有文章”、“我的车”、“没有车”等等。

    【讨论】:

    • 是的,但是我有 %{things},所以文章可以放在 my:“%{things} my”之前。你用过 Rails 翻译吗?
    • 只是为了澄清最后一条评论 - 我可以根据语言更改使用 %{things} 的句子结构。
    • 同意,但在某些语言中,根据它所描述的词,“我的”可能有两个不同的词。我会使用保加利亚语,因为我很熟悉——“我的车”翻译成“Moiata kola”,“我的卡车”翻译成“Moiat kamion”。不是“我的”的直接翻译。所以我还是会把两者分开。
    • 好点。谢谢。请注意,编辑您的答案以包含此具体示例可能是一个好主意。
    • 不能对这个答案进行足够的投票!对字符串的不同部分进行插值以形成一个句子根本无法跨语言一致地工作!
    【解决方案2】:

    您在帖子中描述的做法,即:

    articles:
     one: "Article"
     other: "Articles"
    

    恕我直言是有效和适当的。至少我在我从事的项目中经常遇到它。至于你提到的“乱七八糟”:

      one_l:   "article"
      other_l: "articles"
    

    恕我直言,您不必担心,因为您基本上可以在任何字符串上调用downcase。只要你有给定语言的单数和复数形式,你就很好。

    %{things}的位置不同,这是理所当然的事情。你把它放在合适的地方。例如,在 5 种不同的语言中:

     not_saved:
        one: ! '1 fejl medførte at denne %{resource} ikke kunne gemmes:'
        other: ! '%{count} fejl medførte at denne %{resource} ikke kunne gemmes:'
    
     not_saved:
        one: ! '1 error prohibited this %{resource} from being saved:'
        other: ! '%{count} errors prohibited this %{resource} from being saved:'
    
      not_saved:
        one: ! '1 virhe esti %{resource} tallentamisen:'
        other: ! '%{count} virhettä esti %{resource} tallentamisen:'
    
      not_saved:
        one: ! 'Én feil gjorde at %{resource} ikke kunne lagres:'
        other: ! '%{count} feil gjorde at %{resource} ikke kunne lagres:'
    
      not_saved:
        one: ! '1 fel hindrade denna %{resource} från att sparas:'
        other: ! '%{count} fel hindrade denna %{resource} från att sparas:'
    

    希望有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多