2012-07-03 19 views
2

我希望有人能夠看看這個,因爲我以前從來沒有翻譯過任何英文,所以我不確定是否會出現語法衝突。在RoR中構造翻譯的有效方法?

我:

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) 

我想要做的就是幹起來我的翻譯,也進不了一個整體亂用使用方法:

  • 變複數
  • singularize
  • downcase
  • 利用

似乎在文本中使用的資本化,多元狀態時,模型的最常見的形式,這就是爲什麼我選擇了「公司章程」與「條」或「物品」。你是否贊成在視圖文件上面的方法VS一樣的東西:

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

..這可能會發展成這個爛攤子:

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

回答

2

不同的語言,有句話是如何建立不同的規則。幹翻你的翻譯可能會導致外語在語法上不正確的句子。我建議一次堅持一個邏輯塊的文本。例如段落,句子,表達或詞語。

例如,假設在您希望將應用程序翻譯成的每種語言中,「我的」這個詞總是出現在「articles」之前,並且「my」只有一個單詞。

在某些語言中,「my」的版本可能取決於與之相關的單詞。我會使用保加利亞語,因爲我知道它很好 - 「我的車」翻譯爲「Moiata kola」,「My truck」翻譯爲「Moiat kamion」。不是直接翻譯「我的」。

此外,在某些語言中,您可能不得不說「我的文章」出現在「我的」之前的「我的文章」。您可以將「文章」配置爲在不同語言的「我的」之前,但如果您的翻譯包含多個變量,則可能會出現問題。

我會爲這些中的每一個分別設置一行:「我的文章」,「沒有文章」,「我的車」,「沒有車」等等。

+0

是的,但我有%{}的東西,所以文章可以在我的面前來: 「%{}事情我」。你使用過Rails翻譯嗎? –

+0

只是爲了澄清最後的評論 - 我可以根據語言改變使用%{things}的句子的結構。 –

+0

同意,但在某些語言中,根據它所描述的詞可能有兩個不同的「我的」單詞。我會使用保加利亞語,因爲我知道它很好 - 「我的車」翻譯爲「Moiata kola」,「My truck」翻譯爲「Moiat kamion」。不是直接翻譯「我的」。所以我仍然保持兩個分開。 –

1

您在您的文章中描述過的做法,即:

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:' 

希望幫助

相關問題