Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix fallback bug #475

Merged
merged 2 commits into from
Oct 26, 2017
Merged

fix fallback bug #475

merged 2 commits into from
Oct 26, 2017

Conversation

kilolumen
Copy link

Fix #465 #460

@kilolumen kilolumen closed this Oct 26, 2017
@kilolumen kilolumen deleted the fix_fallback branch October 26, 2017 03:32
@PikachuEXE
Copy link

What does it archive?
I already added some test cases in #465

@kilolumen
Copy link
Author

kilolumen commented Oct 26, 2017

@PikachuEXE
old: locales = ["zh-Hans-TW", "zh", "zh-Hans", "en"]
fix: locales = ["zh-Hans-TW", "zh-Hans", "zh", "en"]

I18n.translations = {
    "zh": {
        "cat":  "貓" // Chinese Traditional
    },
    "zh-Hans": {
        "cat": "猫" // Chinese Simplified
    }
}

i18n.js line: 400

while (locales.length) {
      locale = locales.shift();
      scopes = fullScope.split(this.defaultSeparator);
      translations = this.translations[locale];
      // ....
}

Becuase shift() removes the first element from an array and returns it. so
old: Locale will assign "zh", and it will return "貓".
fix: Locale will assign "zh-Hans", and it will return "猫".

@kilolumen kilolumen restored the fix_fallback branch October 26, 2017 04:20
@kilolumen kilolumen reopened this Oct 26, 2017
@PikachuEXE
Copy link

OK Please add a test case to ensure this fix is working

@kilolumen
Copy link
Author

I already added a test case.

@PikachuEXE PikachuEXE merged commit 11c27b6 into fnando:master Oct 26, 2017
@PikachuEXE
Copy link

Thanks, will release soon

@PikachuEXE
Copy link

3.0.2 released (gem + npm)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants