Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic model and translate #15

Open
xavadu opened this issue Nov 7, 2013 · 1 comment
Open

Dynamic model and translate #15

xavadu opened this issue Nov 7, 2013 · 1 comment

Comments

@xavadu
Copy link

xavadu commented Nov 7, 2013

Hello, i want try to do something like that, but i think that the service don't support it, i want use dynamic data (model) passed by a filter and later translate it.

example:

<span>In the date that you choose 12/11/2013 you will receive the package.</span>

the date '12/11/2013' is a model, so:
<foo ng-model="date"></foo> <span>In the date that you choose { date | date:'medium' } you will receive the package.</span>

how i can use this service to translate this sentence? i have a dynamic value
{ "key": "_Message_", "value": "In the date that you choose {0} you will receive the package." }

but it should be passed by a filter first and later to the i18n filter (like the date change on fly i think that i should use the i18n filter and not the directive)

Thanks

@xavadu
Copy link
Author

xavadu commented Nov 11, 2013

solved, i modify the filter like that


// simple translation filter
// usage {{ 'TOKEN|VAR1|VAR2'| i18n }}
.filter('i18n', ['localize', function (localize) {
return function (token) {
var values = token.split('|');
if (values.length >= 1) {
// construct the tag to insert into the element
var tag = localize.getLocalizedString(values[0]);
// update the element only if data was returned
if ((tag !== null) && (tag !== undefined) && (tag !== '')) {
if (values.length > 1) {
for (var index = 1; index < values.length; index++) {
var target = '{' + (index - 1) + '}';
tag = tag.replace(target, values[index]);
}
}
// insert the text into the element
return tag;
};
}
};
}])

{
        'key' => '_ExchangeRateFrom_',
        'value' => 'Exchange rate {0} from',
        'description' => 'The exchange rate shown near to the calendar'
}
`
{ ('_ExchangeRateFrom_|'+ (baseExchangeRate | enhancedCurrency:'':4) ) | i18n }
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant