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

Problem with custom translations #35

Closed
elecoest opened this issue Nov 22, 2013 · 4 comments
Closed

Problem with custom translations #35

elecoest opened this issue Nov 22, 2013 · 4 comments

Comments

@elecoest
Copy link

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

@jkbrzt
Copy link
Owner

jkbrzt commented Nov 24, 2013

@elecoest can you please post a code example here and describe what the problem is?

@elecoest
Copy link
Author

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 :

TypeError: 2 is not an object
return result.call(this, func.apply(_, args));

in underscore.js

@jkbrzt
Copy link
Owner

jkbrzt commented Nov 24, 2013

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

@jkbrzt jkbrzt closed this as completed Nov 24, 2013
@elecoest
Copy link
Author

Nice job. It's work fine :)
thanks

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

2 participants