# Translation in translationvariable

**URL:** <https://www.ruby-forum.com/t/translation-in-translationvariable/199689>\
**Category:** Rails I18n\
**Created:** [November 26, 2010, 1:04pm UTC](https://www.ruby-forum.com/t/translation-in-translationvariable/199689 "2010-11-26T13:04:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 26, 2010, 1:04pm UTC](https://www.ruby-forum.com/t/translation-in-translationvariable/199689/1 "2010-11-26T13:04:44Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![philipjkim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@philipjkim](https://www.ruby-forum.com/u/philipjkim)\
**Post date:** [November 26, 2010, 4:31pm UTC](https://www.ruby-forum.com/t/translation-in-translationvariable/199689/2 "2010-11-26T16:31:43Z")

</div>

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

1. there aren’t that many general rules that apply to language, all of  
the time, spoken languages have tons of exceptions for probably any rule  
you’d name
2. even if there are such rules we as developers don’t know them -  
that’s why there are translators

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))

---

<div class="post-metadata">

**Author:** ![philipjkim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@philipjkim](https://www.ruby-forum.com/u/philipjkim)\
**Post date:** [November 26, 2010, 6:04pm UTC](https://www.ruby-forum.com/t/translation-in-translationvariable/199689/3 "2010-11-26T18:04:26Z")

</div>

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.html.erb

\<%= 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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![philipjkim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@philipjkim](https://www.ruby-forum.com/u/philipjkim)\
**Post date:** [November 27, 2010, 8:00am UTC](https://www.ruby-forum.com/t/translation-in-translationvariable/199689/4 "2010-11-27T08:00:46Z")

</div>

Have you read i18n guide [Internationalization (I18n) — Ruby on Rails Guides](http://guides.rubyonrails.org/i18n.html) ?🙂

2010/11/26 Philip K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid).  
> To unsubscribe from this group, send email to  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rails-i18n?hl=en](http://groups.google.com/group/rails-i18n?hl=en).

---

<div class="post-metadata">

**Author:** ![philipjkim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@philipjkim](https://www.ruby-forum.com/u/philipjkim)\
**Post date:** [November 26, 2010, 6:57pm UTC](https://www.ruby-forum.com/t/translation-in-translationvariable/199689/5 "2010-11-26T18:57:04Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![philipjkim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f14d63/32.png) [@philipjkim](https://www.ruby-forum.com/u/philipjkim)\
**Post date:** [March 26, 2012, 2:41pm UTC](https://www.ruby-forum.com/t/translation-in-translationvariable/199689/6 "2012-03-26T14:41:51Z")

</div>

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

1. There isn’t that a lot of all-purpose rules that pertain to verbal  
communication, all of the time, spoken languages have plenty of  
exceptions for almost certainly any rule you’d name
2. Even if there is such policy we as developers don’t know them -  
That’s why there are translators

Therefore one should agree to translators to translate every single cord  
The way they want - even if there’s heaps of repetition then.

> **[Professional Human Translation, Subtitling & Interpretation Services](https://translatebyhumans.com/)**
>
> High-quality human translation, localisation, subtitling, and interpretation services provided by experts in 180+ languages
