compound icon indicating copy to clipboard operation
compound copied to clipboard

i18n, t helper array localized tokens fail

Open lovejaco opened this issue 13 years ago • 4 comments

for example <%= t(['user.welcome', user.name]) %> is fine but

var tokens = ['user', 'test']; <%= t(['user.welcome', tokens ]) %> is fail

T(global) method in i18n.js function translate(path, locale, defaultValue) { ... substitute = path; path = substitute.shift();

// i think need to add this code
// substitute = substitute.shift()
}

lovejaco avatar Feb 13 '13 07:02 lovejaco

It should not work in both cases. Correct usage:

t('user.welcome');

or

t('user.welcome', 'Default welcome message');

1602 avatar Feb 13 '13 08:02 1602

sorry .. my english skill is poor but there is no problem just read i mean,

example language resource upload: "Uploaded at % by %"

i try helper t( [ 'upload', ['time', 'user' ]) then output is Uploaded at time, use by %

because

substitute = path; substitute = [ 'upload', ['time', 'user' ] ] path = substitute.shift(); substitute = [ ['time', 'user' ] ]

substitute.forEach(function(substitution) { .. // output is " Uploaded at time, use by %"
// i think need to add this code substitute = substitute.shift(); then substitute = ['time', 'user' ] }

lovejaco avatar Feb 13 '13 08:02 lovejaco

Yep, i see what you mean now, thanks for explanation, i just forgot about this feature. Yes, first argument could be array of [pattern, substitution1, ..., substN]. Not [pattern, [s1, s2, s3]] - this is why you have a problem. I believe no code changes required.

On Wed, Feb 13, 2013 at 4:30 PM, Sung Yeol Yim [email protected]:

sorry .. my english skill is poor but there is no problem just read i mean,

example language resource upload: "Uploaded at % by %"

i try helper t( [ 'upload', ['time', 'user' ]) then output is Uploaded at time, use by %

because

substitute = path; substitute = [ 'upload', ['time', 'user' ] ] path = substitute.shift(); substitute = [ ['time', 'user' ] ]

substitute.forEach(function(substitution) { .. // output is " Uploaded at time, use by %"

// i think need to add this code substitute = substitute.shift(); then substitute = ['time', 'user' ] }

— Reply to this email directly or view it on GitHubhttps://github.com/1602/compound/issues/391#issuecomment-13478950.

anatoliychakkaev avatar Feb 13 '13 08:02 anatoliychakkaev

thanks,i understand now

i just want use array type arguments .

so i use this.. <%- t(['user.welcome'].concat( someArray)] ) %>

lovejaco avatar Feb 13 '13 09:02 lovejaco