Reputation:
I was hoping somebody could look this over, as I've never translated anything but English before, and so I'm not sure if there would be grammatical conflicts.
I have:
en:
articles:
name: "Articles"
comments:
name: "Comments"
# things
no_results: "There are no %{things}"
my: "My %{things}"
Then in a view file, for example:
#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)
What I'm trying to do is DRY up my translations, but also not get into a whole mess with using methods:
It seems the most common form of a model when used in text is capitalized and pluralized, that is why I chose "Articles" vs "Article" or "article". Would you favor the above methods in view files vs something like:
articles:
one: "Article"
other: "Articles"
..which might develop into this mess:
articles:
one: "Article"
other: "Articles"
one_l: "article"
other_l: "articles"
Upvotes: 2
Views: 115
Reputation: 5095
The practice you've described in your post, i.e:
articles:
one: "Article"
other: "Articles"
is imho valid and proper. At least I often encountered it on the projects I have worked on. As for the "mess" you've mentioned:
one_l: "article"
other_l: "articles"
Imho you shouldn't worry about it because you can basically call a downcase
on any string. As long as you have singular and plural form in a given language you're good.
As for the different placement of %{things}
, it is natural thing. You place it where it fits. For example, in 5 different languages:
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:'
Hope that helps
Upvotes: 1
Reputation: 51
Different languages have different rules for how sentences are built. DRYing up your translations may result in grammatically incorrect sentences in foreign languages. I would suggest sticking to a logical block of text at a time. e.g. paragraph, sentence, expression or word.
For example you are assuming that in every language that you want your application to be translated into, the word "my" will always come before the word "articles" and that there is only one word for "my".
In some languages the version of "my" may depend on the word that goes along with it. I'll use Bulgarian because I know it well - "My car" translates into "Moiata kola" and "My truck" translates into "Moiat kamion". Not a straight forward translation of "my".
Also it may be that in some languages you would have to say something like "Articles of mine" where "articles" comes before "my". You can configure "articles" to come before "my" for different languages, but it might become problematic if your translation contains more than one variable.
I would have a separate line for each of these: "my articles", "there are no articles", "my cars", "there are no cars" and so on.
Upvotes: 2