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

Provide instructions for i18n #403

Open
arturo-ojeda opened this issue Jun 3, 2020 · 6 comments
Open

Provide instructions for i18n #403

arturo-ojeda opened this issue Jun 3, 2020 · 6 comments

Comments

@arturo-ojeda
Copy link

Hi there.

I was trying to add localization for Spanish today but found it to be a bit hard.

At fist, I thought I just needed to add an SPANISH Language constant on i18n.ts, translate it and export it. I was then able to import it on my test cases but only the translated dayNames and monthNames worked, not the tokens.

The main idea was to translate the toText() method but I figured that I could maybe perform the full job and translate it for parsing too but neither method worked.

This is one example of one of the test results:

  AssertionError: expected 'every week until 10. Noviembre, 2012' to equal 'cada semana hasta 10. Noviembre, 2012'

  + expected - actual

  -every week until 10. Noviembre, 2012
  +cada semana hasta 10. Noviembre, 2012

What is not clear to me is how to translate the tokens. I tried using some breakpoints to understand it but I didn't get it so I thought maybe I should ask.

I tried translating a token's key, value and both, without getting a positive result.

I'll be glad to complete a full translation if more instructions are provided on how to do it.

Thanks.

@michaelkrog
Copy link

Hi.

I managed to make a danish translation years back. I am not sure if the api has changed since then (I am still using an old version). This is how I did it in Angularjs.

export interface IRRuleService {
    toText(rule: any);
}

export class RRuleService {

    // date-related translations
    strings: any = {
        da: {
            'every': 'hver',
            'until': 'indtil',
            'day': 'dag',
            'days': 'dage',
            'weekdays': 'hverdage',
            'week': 'uge',
            'weeks': 'uger',
            'year': 'år',
            'years': 'år',
            'on': 'på',
            'month': 'måned',
            'months': 'måned',
            'on the': 'på den',
            'and': 'og',
            'nd': '.',
            'rd': '.',
            'st': '.',
            'th': '.',
            'last': 'sidste'
        }
    };

    i18n: any = {};

    /** @ngInject */
    constructor(private $locale: ng.ILocaleService, private $log: ng.ILogService) {
        $log.info('Initializing RRuleService');
        this.i18n.dayNames = angular.copy($locale['DATETIME_FORMATS']['DAY']);
        this.i18n.monthNames = angular.copy($locale['DATETIME_FORMATS']['MONTH']);

        var language = this.getLanguage();

        switch (language) {
            case 'da':
                for (var i = 0; i < this.i18n.dayNames.length; i++) {
                    this.i18n.dayNames[i] = this.i18n.dayNames[i] + 'e';
                }
                break;
        }

        if (angular.isDefined(this.strings[language])) {
            this.i18n.strings = this.strings[language];
        }
    }

    private getLanguage(): string {
        return this.$locale.id.split('_')[0];
    }

    public toText(rule) {
        if (rule == null) {
            return null;
        }

        var that = this;
        return rule.toText((id) => {
            var language: string = this.getLanguage();
            return angular.isDefined(that.i18n.strings) ? that.i18n.strings[id] : id;
        }, this.i18n);
    }
}

@arturo-ojeda
Copy link
Author

Hi Michael. Thank you for this, will take a look a it.

@blogui91
Copy link

blogui91 commented Oct 6, 2020

@arturo-ojeda Hello sir, could you solve this issue according to michaelkrog's answer?

@arturo-ojeda
Copy link
Author

@arturo-ojeda Hello sir, could you solve this issue according to michaelkrog's answer?

Sorry @blogui91 , nope, I ended up going with a different solution.

@iamkinetic
Copy link

@arturo-ojeda Hello sir, could you solve this issue according to michaelkrog's answer?

Sorry @blogui91 , nope, I ended up going with a different solution.

What was your solution?

@arturo-ojeda
Copy link
Author

@iamkinetic , the solution in our case was a bit hacky and only used a sub-set of the rrule spec, that's why I believe it wasn't useful to share it over here because it is not reusable and is only specific to our use case.

I'm not working in that project anymore so I don't have access to the code we used, but I believe it wouldn't be useful for other projects anyway.

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

4 participants