Skip to content

Use the plural form appropriate to the message, not the requested locale#34

Open
benjaminwinger wants to merge 1 commit into
kikito:masterfrom
benjaminwinger:plural_fix
Open

Use the plural form appropriate to the message, not the requested locale#34
benjaminwinger wants to merge 1 commit into
kikito:masterfrom
benjaminwinger:plural_fix

Conversation

@benjaminwinger

Copy link
Copy Markdown

If the message isn't available and the fallback is used, it would otherwise use the plural function for the requested locale, not the fallbackLocale.

This bug causes incorrect output, or even crashes if the requested locale and the fallback locale are different enough.

E.g.

i18n = require 'i18n'
i18n.load({en = {
    foo = {
        one = "A thing",
        other = "%{count} things",
    }
}})

print(i18n.translate("foo", {count=0})) -- "0 things"
i18n.setLocale("fr")
print(i18n.translate("foo", {count=0})) -- "A thing"
i18n.setLocale("pl")
print(i18n.translate("foo", {count=0})) --[[
luajit: i18n/interpolate.lua:7: attempt to index local 'string' (a nil value)
stack traceback:
        i18n/interpolate.lua:7: in function 'interpolateValue'
        i18n/interpolate.lua:52: in function 'localizedTranslate'
        i18n/init.lua:140: in function 'translate'
        test.lua:13: in main chunk
        [C]: at 0x560b0c93a238
]]

If the message isn't available and the fallback is used, it would otherwise use the plural function for the requested locale, not the fallbackLocale
flexiondotorg added a commit to Oval-Tutu/smiti18n that referenced this pull request Jan 12, 2025
If the message isn't available and the fallback is used, it would otherwise use the plural function for the requested locale, not the fallbackLocale

- Pass locale through pluralization chain
- Separate custom and default pluralization handling
- Improve pluralization accuracy for mixed-locale usage
- Add tests for Polish locale pluralization

Cherry-picked from kikito/i18n.lua#34
flexiondotorg added a commit to Oval-Tutu/smiti18n that referenced this pull request Jan 12, 2025
If the message isn't available and the fallback is used, it would otherwise use the plural function for the requested locale, not the fallbackLocale

- Pass locale through pluralization chain
- Separate custom and default pluralization handling
- Improve pluralization accuracy for mixed-locale usage
- Add tests for Polish locale pluralization

Cherry-picked from kikito/i18n.lua#34
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.

1 participant