i18n dynamic interpolation arguments

Talgat Medetbekov

Let's say that I have a field witch consist of multiple parts separated by a semicolon (;). For example, this would look like the following:

'range_numeric; 10; 100'
'length_numeric; 5'

The first part will be the key to the translation and any subsequent parts will be interpolation values to be filled into the text. Basically it is passed as a named argument, but I don't want to define keys for each interpolation values and I'm trying to use I18n as following:

en:
 length_numeric: "%{1} digits"
 range_numeric: "%{1} - %{2} digits"

I was trying to pass interpolation values like following:

t(:range_numeric, 10, 100) # returns "%{1} - %{2} digits" 

So, is this possible doing this way? Any suggestions ?

sawa

I don't know how to interface with rails, but interpolating a string with an array is easy. Use %s for simple string substitution. You can even have finer control by using an appropriate format syntax.

"%s - %s digits" % [10, 100]
# => "10 - 100 digits"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related