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
Problem with custom translations #35
Comments
@elecoest can you please post a code example here and describe what the problem is? |
Here is the code : <!doctype html>
<title>trad tests</title>
<script src="underscore.js"></script>
<script src="rrule.js"></script>
<script src="nlp.js"></script>
<script type='text/javascript'>
// Date-related translations
var portuguese = {
dayNames: [
"Domingo",
"Segunda-Feira",
"Terça-feira",
"Quarta-feira",
"Quinta-feira",
"Sexta-feira",
"Sábado"
],
monthNames: [
"Janeiro",
"Fevereiro",
// …
]
// `tokens` are only needed for `RRule.fromText`
};
// Strings
var portugueseStrings = {
'every': 'cada',
'until': 'até',
'day': 'dia',
'days': 'dias',
'week': 'semana',
'weeks': 'semanas',
'on': 'em'
// …
};
var gettext = function(id) {
// Return pt. string, default to english.
return portugueseStrings[id] || id;
};
var rule = new RRule(RRule.WEEKLY, {
interval: 5,
byweekday: [RRule.MO, RRule.FR],
dtstart: new Date(2012, 1, 1, 10, 30),
until: new Date(2012, 12, 31)
});
console.log(rule.toText());
// => every 5 weeks on Monday, Friday until January 31, 2013
console.log(rule.toText(null, gettext, portuguese));
// => cada 5 semanas em Segunda-Feira, Sexta-feira até Janeiro 31, 2013
</script> I have this error :
in underscore.js |
I see, the example in the other thread was for an older version of RRule. This works with v2.0+: // Date-related translations
var portuguese = {
dayNames: [
"Domingo",
"Segunda-Feira",
"Terça-feira",
"Quarta-feira",
"Quinta-feira",
"Sexta-feira",
"Sábado"
],
monthNames: [
"Janeiro",
"Fevereiro",
// …
]
// `tokens` are only needed for `RRule.fromText`
};
// Strings
var portugueseStrings = {
'every': 'cada',
'until': 'até',
'day': 'dia',
'days': 'dias',
'week': 'semana',
'weeks': 'semanas',
'on': 'em'
// …
};
var gettext = function(id) {
// Return pt. string, default to english.
return portugueseStrings[id] || id;
};
var rule = new RRule( {
freq: RRule.WEEKLY,
interval: 5,
byweekday: [RRule.MO, RRule.FR],
dtstart: new Date(2012, 1, 1, 10, 30),
until: new Date(2012, 12, 31)
});
console.log(rule.toText());
// => every 5 weeks on Monday, Friday until January 31, 2013
console.log(rule.toText(gettext, portuguese));
// => cada 5 semanas em Segunda-Feira, Sexta-feira até Janeiro 31, 2013 |
Nice job. It's work fine :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've tried NLP but it's failed.
I've post my code on 13# issue without any response
#13 (comment)
Anybody hove the answer ?
elecoest
The text was updated successfully, but these errors were encountered: