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

core:text/i18n procs get_*_section() should have 1 as number default rather than 0 #3451

Closed
mgavioli opened this issue Apr 19, 2024 · 1 comment

Comments

@mgavioli
Copy link
Contributor

Context

Any, as it refers to inner working of the core library, regardless of any context.

  • Operating System & Odin Version:
  • Odin: dev-2024-04-nightly:aab122ede
  • OS: Linux Mint 21.3, Linux 5.15.0-101-generic
  • CPU: Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz
  • RAM: 15913 MiB
  • Backend: LLVM 17.0.6

Expected Behaviour

In core:text/i18n, procs get_single_section() and get_by_section() are documented to default to a singular case when no plural number is provided (see for instance get_section_single_section().

Current Behaviour

They, rather, default to a 'none' plural number (0). Unless a specific pluraliser is used, the 'none' case is (correctly for a default) typically treated as a plural. So, defaulting the number parameter to 0 generically results in a plural form being chosen if available. Note that the number parameter refers to the amount of 'things' being considered in the message, not to the index of the translation slot (which indeed is usually 0 for the singular form).

Failure Information (for bugs)

There is no failure, rather the wrong message is typically returned, if plural forms are available.

Steps to Reproduce

  1. compile the attached main.odin source file (in the i18n_bug.zip file: github filters out most file extensions)
  2. place in the same directory the attached sample.mo file and the compiled executable and run it
  3. output:
This is message 1 - plural
This is message 1 - plural

While the expected output is

This is message 1
This is message 1 - plural

which is obtained if the number default values in the aforementioned procs are changed to 1.

For completeness, this is the main.odin source:

package i18n_bug
import "core:fmt"
import "core:path/filepath"
import "core:os"
import "core:strings"
import "core:text/i18n"

main :: proc()
{
	// build the path of a message catalogue parallel to the executable
	app_path:	= os.args[0]
	cat_path:	= strings.join({filepath.dir(app_path), "sample.mo"}, "/")
	defer delete(cat_path)

	// parse and load the message catalogue without any specific pluraliser
	i18n_err:	i18n.Error
	i18n.ACTIVE, i18n_err	= i18n.parse_mo_file(cat_path)
	if (i18n_err == i18n.Error.None || i18n_err == nil)
	{
		defer i18n.destroy(i18n.ACTIVE)
		// The "Message1" is pluralised in the catalogue
		fmt.println(i18n.get("Message1"))		// no number: shall return the singular form
		fmt.println(i18n.get("Message1", 2))	// a plural number: shall return the plural form
	}
	else	do fmt.println("Error parsing message catalogue:", i18n_err)
}

The attached sample.mo file has been obtained by compiling with POEdit the following sample.po file:

msgid ""
msgstr ""
"Project-Id-Version: 0.1.0\n"
"PO-Revision-Date: 2024-04-13 11:13+0200\n"
"Last-Translator: Someone <someone@somewhere.com>\n"
"Language-Team: English\n"
"Language: en_IE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Message1"
msgid_plural "Message1/plural"
msgstr[0] "This is message 1"
msgstr[1] "This is message 1 - plural"

i18n_bug.zip

Kelimion added a commit that referenced this issue Apr 19, 2024
…fault

Fix #3451 - `core:text/i18n` default `number` value in `get_*_section`
@Kelimion
Copy link
Member

Good catch. Merged.

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

No branches or pull requests

2 participants