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

Issues with core:text/i18n.parse_mo_from_bytes(): 2. number of plural forms #3591

Closed
mgavioli opened this issue May 16, 2024 · 2 comments · Fixed by #3595
Closed

Issues with core:text/i18n.parse_mo_from_bytes(): 2. number of plural forms #3591

mgavioli opened this issue May 16, 2024 · 2 comments · Fixed by #3595
Assignees

Comments

@mgavioli
Copy link
Contributor

Context

Odin: dev-2024-05-nightly:2250eb3e7
OS: Linux Mint 21.3, Linux 5.15.0-106-generic
CPU: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz
RAM: 15913 MiB
Backend: LLVM 17.0.6

Expected Behaviour

In .mo files, the number of untranslated plural forms for pluralised messages files is fixed to 2 (for non pluralised messages is fixed to 1).

The number of translated plural forms can be any number from 1 (for languages without any plural, like Chinese) to any conventional limit; the documented maximum is 6 for Welsh (and other languages); the maximum acceptable number of plural forms hard coded in core:text/i18n is 10.

The procedure should properly parse .mo files in which the number of untranslated (always 2) and translated (1 - 10) plural forms is different.

Current Behaviour

The procedure rejects .mo files in which entries have a different number of plural forms between translated and untranslated messages, as it can be seen here.

Steps to Reproduce

  1. Compile the provided main.odin source file (in the attached ZIP file) in the same directory as the provided .mo file.
  2. Run the compiled executable:
  3. it will report an Error parsing message catalogue: MO_File_Incorrect_Plural_Count

Note: the attached ZIP file contains the main.odin source code, a .mo file and the .po file from which it has been compiled via PoEdit.
i18n_num_of_plur_bug.zip

@mgavioli
Copy link
Contributor Author

mgavioli commented May 16, 2024

It seems to me that the simplest fix could be to change the current form of line 97 of gettext.odin from:

if len(keys) != len(vals) || max(len(keys), len(vals)) > MAX_PLURALS {

to

if (len(keys) != 1 && len(keys) != 2) || len(vals) > MAX_PLURALS {

as the number of untranslated string can only be 1 or 2 and the number of translated string can be any as long as it does not exceed the accepted maximum.

@Kelimion
Copy link
Member

I'll be looking at this (and its sibling Issue) tomorrow. Thanks for the repro case and the suggested fix.

Kelimion added a commit to Kelimion/Odin that referenced this issue May 17, 2024
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 a pull request may close this issue.

2 participants