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

Crash with "zh-classical" messages #38

Open
nyurik opened this issue Sep 16, 2020 · 7 comments
Open

Crash with "zh-classical" messages #38

nyurik opened this issue Sep 16, 2020 · 7 comments

Comments

@nyurik
Copy link

nyurik commented Sep 16, 2020

This code crashes because it calls new Intl.PluralRules("zh-classical"), which is an error in Chrome.

try {
  const bb = new Banana('zh-classical', { messages: {} });
  console.error(bb.i18n('zh-classical -- {{PLURAL:$1|$1 aaa|$1 bbb}}', 10))
} catch (err) {
  console.error(err)
}

Error:

index.js:1 RangeError: Incorrect locale information provided
    at new PluralRules (<anonymous>)
    at r.getPluralForm (language.js:51)
    at r.convertPlural (language.js:36)
    at c.plural (emitter.js:134)
    at c.emit (emitter.js:55)
    at emitter.js:54
    at Array.map (<anonymous>)
    at c.emit (emitter.js:54)
    at i.parse (parser.js:13)
    at o.i18n (index.js:28)
@Nikerabbit
Copy link
Member

I fixed a similar issue in https://phabricator.wikimedia.org/T228510

@Nikerabbit
Copy link
Member

The standard language code for zh-classical is lzh.

@nyurik
Copy link
Author

nyurik commented Sep 16, 2020

@Nikerabbit thanks, but the banana lib has an entry for it in

"zh-classical": ["lzh"],
-- shouldn't it automatically handle such things internally? If banana lib is targeting Wikipedia, it should IMO handle every "language-like" prefix Wikipedia has -- i.e. *.wikipedia.org

@Nikerabbit
Copy link
Member

I recommend against using the domain code as language code. There are many exceptions where they do not match. The real language code (queryable via API, mw.config.values.wgContentLanguage, etc.) is better.

@nyurik
Copy link
Author

nyurik commented Sep 16, 2020

@Nikerabbit you assume the code runs in MW, whereas I use it outside of it -- https://dibabel.toolforge.org/ -- and I would have to resolve the domain into the default language. That said, could you explain why there is a fallback file? If its there, I would assume it is supported. Otherwise its a bug to have stuff in it that doesn't work :)

@nyurik
Copy link
Author

nyurik commented Sep 16, 2020

P.S. I just double checked -- https://meta.wikimedia.org/w/api.php?action=sitematrix&formatversion=2 -- zh-classical is the official language code:

        "313": {
            "code": "zh-classical",
            "name": "文言",
            "site": [
                {
                    "url": "https://zh-classical.wikipedia.org",
                    "dbname": "zh_classicalwiki",
                    "code": "wiki",
                    "sitename": "維基大典"
                }
            ],
            "dir": "ltr",
            "localname": "Classical Chinese"
        },

@siddharthvp
Copy link
Collaborator

This is necro-posting, but that's the sitecode, not language code. Going to https://zh-classical.wikipedia.org and hitting mw.config.get('wgContentLanguage') gives lzh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants