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

Language fallbacks #250

Merged
merged 8 commits into from
Dec 21, 2015
Merged

Conversation

rubenswieringa
Copy link
Contributor

Makes languages fall back onto their base language: en_GBen, de_CHde, etc.

Original issue: #210
Original PR: #236

Notable changes:

Let me know if you have any better suggestions for better naming, or if there is anything else that could be improved upon.

crissdev and others added 7 commits October 30, 2015 23:52
- baseLanguage is private because it conflicts with catalog's attribute with the same name
- plural detection is pretty hardcoded, there's no clear way to know if plural is defined or not
…ew function

Removes getStringForm(). See discussion here: rubenv#236 (comment)
@rubenswieringa rubenswieringa mentioned this pull request Dec 19, 2015
@rubenswieringa rubenswieringa changed the title Fallback improvement Language fallbacks Dec 19, 2015
}
return null;
};
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be executed a lot. I suggest adding a simple memoization:

angular.module("gettext").factory("gettextFallbackLanguage", function () {
    var cache = {};
    var pattern = /([^_]+)_[^_]+$/;

    return function (langCode) {
        if (cache[langCode]) {
            return cache[langCode];
        }

        var matches = pattern.exec(langCode);
        if (matches){
            cache[langCode] = matches[1];
            return matches[1];
        }

        return null;
    };
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! Added.

@rubenswieringa
Copy link
Contributor Author

Last few things fixed – all ready for merge then?

@rubenv
Copy link
Owner

rubenv commented Dec 19, 2015

This looks excellent, I will put this through some testing on our projects. If it doesn't throw up any problems (not expecting any), it'll get merged.

@rubenswieringa
Copy link
Contributor Author

Great! Let me know :)

rubenv added a commit that referenced this pull request Dec 21, 2015
@rubenv rubenv merged commit 5f06e57 into rubenv:master Dec 21, 2015
@rubenv
Copy link
Owner

rubenv commented Dec 21, 2015

Works like a charm!

@rubenswieringa rubenswieringa deleted the fallback-improvement branch December 21, 2015 08:57
@rubenv
Copy link
Owner

rubenv commented Dec 21, 2015

Released as v2.2.0. Excellent pull request once again.

This one still needs updating: https://angular-gettext.rocketeer.be/dev-guide/api/angular-gettext/ (website is in git here: https://github.com/rubenv/angular-gettext-website). I'll do that myself in a minute.

Thanks, a lot!

@crissdev
Copy link
Contributor

Great work guys. 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

Successfully merging this pull request may close these issues.

3 participants