Hello,
i need some help I want to use a translation variable in neu
translation.
something like this code:
de:
namespace: “Kunde”
new:
headline: “Kunden anlegen”
submit: “t(namespace) anlegen”
please help me
Hello,
i need some help I want to use a translation variable in neu
translation.
something like this code:
de:
namespace: “Kunde”
new:
headline: “Kunden anlegen”
submit: “t(namespace) anlegen”
please help me
Hey Philip,
tl;dr: you probably don’t wanna do it.
DRY is a principle that applies to code but not translations. When we
abstract our code then we are the ones who are in control of applying
general rules to it. But when it comes to translations we must leave
your translators in control and therefor don’t want to abstract
translations.
The reason for that is that
Therefor one should allow translators to translate every single string
the way they want - even if there’s tons of duplication then.
One practical example where what you’re trying to do could potentially
crash on the floor is when your :namespace translation needs to be
inflected when it’s interpolated (inserted) into this particular
translation for :submit in this particular context on your page.
That said, there are some situations where even Rails does something
similar.
You can do it like this:
de:
new:
submit: “%{namespace} anlegen”
and then
I18n.t(:‘new.submit’, :namespace => I18n.t(:namespace))
Hey Sven,
thanks a lot
I had just another problem.
How to act with partials in translations?
especially with the submit button:
here my problem:
<%= form_for(@customer) do |f| %>
#some code
<%= f.submit t(“new.submit”) %>
<% end %>
#locales/views/customers/de.yml
de:
new:
headline: “Kunden anlegen”
submit: “Kunden anlegen”
edit:
headline: “Kunden bearbeiten”
submit: “Kunden speichern”
How to set the buttons text depents on edit an new
<%= f.submit t(“submit”) %>
thanks to you!
Philip
2010/11/26 Sven F. [email protected]
Have you read i18n guide Rails Internationalization (I18n) API — Ruby on Rails Guides ?
2010/11/26 Philip K. [email protected]:
submit: “t(namespace) anlegen”
please help me
–
You received this message because you are subscribed to the Google G.
“rails-i18n” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected][email protected]
.
For more options, visit this group at
http://groups.google.com/group/rails-i18n?hl=en.
Just like Krzysztof I’d recommend checking out the Rails guide on
Internationalization. IIRC it answers both of the questions you’ve
asked.
You might want to check out the Rails “lazy” translation helper:
t(’.submit’)
Notice the dot at the beginning of the key. This dot is expanded to the
current view path, e.g. on “customers/_form” this key becomes
:‘customers.form.submit’
While we intangible our code then we are the ones who are in organize of
be relevant universal rules to it. But when it comes to translations we
must go away your translators in control and therefore don’t want to
abstract
Translations.
Reason for that is that
Therefore one should agree to translators to translate every single cord
The way they want - even if there’s heaps of repetition then.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs