-
-
Notifications
You must be signed in to change notification settings - Fork 519
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
Documentation for i18n of toText #13
Comments
It's not actually used as of now, you can just pass
The API isn't very nice. You need to create a language definition with date related stuff. The default English one is here.
A crude example (you need the current master, older versions cached the output of
TODO: improve and document the API (perhaps a |
Hm, yeah. There's something missing. Because you can't just translate the words. Depending on the language the order needs to be changed as well, because they have a different grammar. Instead there should be format strings like singular: 'every week on {{dayNames}}',
plural: 'every {{numWeeks}} weeks on {{dayNames}}' That's just a rough example. I know that there are a lot edge cases etc. and that it's probably hard to do right. |
Just came across https://github.com/airbnb/polyglot.js , but there are many other solutions for i18n Some thing that just bit me: In English it's "every week" and "every month". In German it's "jede Woche" and "jeden Monat". Notice the "n". I can't just translate "every", it won't work. Similar thing with passing "st" or "rd" to gettext. It doesn't make any sense. |
Any news or plans? Now that I started using One more thing for the list: Date formats. I want |
I don't understand. In one html file I have this code whith the latests release (2.0). [code] [/code] TypeError: _ is undefined Where I am in wrong ? |
You need another library called underscorejs. I'm on my phone otherwise I would have given you a link. On Oct 30, 2013, at 11:54 PM, elecoest [email protected] wrote: I don't understand. In one html file I have this code whith the latests release (2.0). <!doctype html> trad tests TypeError: _ is undefined var defaults = .clone(RRule.DEFAULTOPTIONS); Where I am in wrong ? — |
ok, i'd placed undesrcore.js in third position... |
Sorry but this way is ak for every body ? Nobody has this error before ? Thanks a lot for your help. |
Hi, I'm trying to get i18n for german, but I can not find what strings are used in "gettext" since the link is broken. I tried to look on the sources but I could find it anything. Thanks! |
|
Would be nice to have some documentation how to use it. I've translated to german, but it's looks wrong: const germanStrings = {
every: 'jedes',
until: 'bis',
day: 'Tag',
days: 'Tage',
week: 'Woche',
weeks: 'Wochen',
on: 'ein',
in: 'in',
'on the': 'auf dem',
for: 'für',
and: 'und',
or: 'oder',
at: 'bei',
last: 'zuletzt',
'(~ approximate)': '(~ approximativ)',
times: 'Zeiten',
time: 'Zeit',
minutes: 'Minuten',
hours: 'Stunden',
weekdays: 'Wochentage',
weekday: 'Wochentag',
months: 'Monate',
month: 'Monat',
years: 'Jahre',
year: 'Jahr'
}; const RRULE_GERMAN = {
dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
monthNames: [
'Januar',
'Februar',
'März',
'April',
'Mai',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'Dezember'
]
}; const gettext = id => {
return germanStrings[id] || id;
};
const rruleText = rule.toText(id => {
gettext(id);
}, RRULE_GERMAN); |
Any updates? How to translate text to other language? |
I think the i18n of this library, as of now, is fundamentally flawed. Things like
are absolutely necessary for some final user experience usage, in different languages. I'd recommend implementing the logic in this alternative (as mentioned by @wakirin in this post). It would really bring the usage of this library up, since, at this moment, this logic must be done manually, in order to create some usable i18n logic. UPDATE: after crawling the code, I found a way to do what I wanted, which, for my language, "solved" it. Just for future reference, I'll leave here a list of all the keys you must translate on the getText method you pass on.
|
@gongAll Thanks,
|
Will there be an update on this matter ? I have to translate into Japanese; the words order is significantly different, so I have no idea how to proceed... |
@shivakumars |
I tried adding the mentioned library as a dependency, still getting the error. Can you help me with an example, please. |
|
Thank you 🙏 . This worked. |
How to setup this? |
I think these could be better translation options.
I have not tested every possibility as only use daily weekly or yearly stuff. Also noted that things like "every third monday every month ..." is no included at all yet? |
Works like magic. |
@sberryman @jakubroztocil @Prinzhorn @shivakumars @elecoest I'm using rrule.toText() to get a human text of a frequency, and I need to support multiple languages |
So the behavior indeed seems a bit odd. I tried copying the dictionary from the i18n.ts file and replicating it in different languages, then passing it to the So while the week/month names get correctly translated, the rest doesn't. The oddity, IMO, starts with the This function returns translations for different parts of the stringified RRule, e.g. "every" or "for". The default implementation of this function solely returns So it turns out, the library itself doesn't even seem to make use of the Regular Expressions inside To make it work correctly, I created a custom So theoretically, we could just translate each ID to our desired language. So a possible solution would be: import { RRule } from 'rrule';
interface Language {
dayNames: string[];
monthNames: string[];
tokens: {
[k: string]: RegExp;
};
getTextDict: { [k: string]: string }
}
const GERMAN: Language = {
dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
monthNames: [
'Januar',
'Februar',
'März',
'April',
'Mai',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'Dezember',
],
tokens: {
...
},
getTextDict: {
th: '.',
every: 'alle',
days: 'tage',
weekdays: 'werktage',
weeks: 'wochen',
hours: 'stunden',
minutes: 'minuten',
months: 'monate',
years: 'jahre',
day: 'tag',
weekday: 'werktag',
week: 'woche',
hour: 'stunde',
minute: 'minute',
month: 'monat',
year: 'jahr',
on: 'am',
'on the': 'am',
at: 'um',
the: 'der',
first: 'erste',
second: 'zweite',
third: 'dritte',
last: 'letzter',
for: 'für',
time: 'mal',
times: 'mal',
until: 'bis',
}
};
export function stringifyRepetition(
rrule: RRuleConfig,
language: 'en' | 'de'
) {
const rrule = new RRule(rrule);
if (language === 'en') {
return rrule.toText();
}
const langStrings = GERMAN;
const getText = (id: any) => {
return langStrings.tokens[id] || id.toString();
};
return rrule.toText(getText, langStrings);
}
Unfortunately, this approach doesn't work well with e.g. German, as words cannot be just replaced with their german equivalent. The So I fear the only viable solution is to roll your own implementation. |
I'm going to add a coin to this issue. I needed to translate the result of My needs were limited. I've limited myself to I preferred to rely on a true i18n lib, I made a small function to correctly pass values (directly based on an instance of // $format is the svelte-i18n method to get translation
// $date same for date
export function humanizeRRule(rule) {
return $format(`humanized rrule`, {
values: {
freq: freqEnum[rule.options.freq],
localizedFreq: $format(freqEnum[rule.options.freq], {
values: { interval: rule.options.interval },
}),
count: $format("{count}", { values: { count: rule.options.count || 0 } }),
until:
rule.options.until && $date(rule.options.until, { dateStyle: "long" }),
},
});
}
And most important is the translation keys. In English{
"humanized rrule": "{freq, select, other {every} } {localizedFreq}{count}{until, select, null {} false {} other { until {until}}}",
"{count}": "{count, plural, =0 {} =1 { 1 time} other { # times}}",
"YEARLY": "{interval, plural, =1 {year} other {# years}}",
"MONTHLY": "{interval, plural, =1 {month} other {# months}}",
"WEEKLY": "{interval, plural, =1 {week} other {# weeks}}",
"DAILY": "{interval, plural, =1 {day} other {# days}}",
"HOURLY": "{interval, plural, =1 {hour} other {# hours}}",
"MINUTELY": "{interval, plural, =1 {minute} other {# minutes}}",
"SECONDLY": "{interval, plural, =1 {second} other {# seconds}}"
} French{
"humanized rrule": "{freq, select, YEARLY {tous les} MONTHLY {tous les} WEEKLY {toutes les} DAILY {tous les} HOURLY {toutes les} MINUTELY {toutes les} SECONDLY {toutes les} other {} } {localizedFreq}{count}{until, select, null {} false {} other {, jusqu'au {until}}}",
"{count}": "{count, plural, =0 {} =1 {, 1 fois} other {, # fois}}",
"YEARLY": "{interval, plural, =1 {ans} other {# ans}}",
"MONTHLY": "{interval, plural, =1 {mois} other {# mois}}",
"WEEKLY": "{interval, plural, =1 {semaines} other {# semaines}}",
"DAILY": "{interval, plural, =1 {jours} other {# jours}}",
"HOURLY": "{interval, plural, =1 {heures} other {# heures}}",
"MINUTELY": "{interval, plural, =1 {minutes} other {# minutes}}",
"SECONDLY": "{interval, plural, =1 {secondes} other {# secondes}}"
} And more exotic, Chinese(mix between Arabic and Chinese number. It can certainly be improved) {
"humanized rrule": "{freq, select, other {每} }{localizedFreq}{count}{until, select, null {} false {} other {直到{until}}}",
"{count}": "{count, plural, =0 {} =1 {1次} other {一共#次}}",
"YEARLY": "{interval, plural, =1 {年} other {#年一次}}",
"MONTHLY": "{interval, plural, =1 {月} other {#月一次}}",
"WEEKLY": "{interval, plural, =1 {周} other {#周一次}}",
"DAILY": "{interval, plural, =1 {天} other {#天一次}}",
"HOURLY": "{interval, plural, =1 {小时} other {#小时一次}}",
"MINUTELY": "{interval, plural, =1 {分钟} other {#分钟一次}}",
"SECONDLY": "{interval, plural, =1 {秒} other {#秒一次}}"
} I'm pretty sure we can adapt it to german or other language and continue to implement others options. |
I need this as well... |
Please add better documentation about i18n of the
toText()
method.today
parameter?gettext
?dayNames
andmonthNames
, but that's only part of it.Thank you for creating this lib!
The text was updated successfully, but these errors were encountered: