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

Plurals export into po file #88

Open
kuzminT opened this issue Oct 26, 2023 · 2 comments
Open

Plurals export into po file #88

kuzminT opened this issue Oct 26, 2023 · 2 comments

Comments

@kuzminT
Copy link

kuzminT commented Oct 26, 2023

Please describe your issue

We're trying to use this package to parse translations from PO files or export them into PO. When we use parsing, it's clear and works well. Now I'm trying to create a new PO and have managed to do it with a string format, but there are some troubles with plurals. I couldn't find any example of how to work with them. Instead of getting one key and several translation variants for it, I have several separate keys and translations. Also, most of the properties for working with objects are private and I can't use them.
So I'm doing something like this:

po := gotext.NewPo()
domain := po.GetDomain()
for i := range translations {
   domain.SetN(key.Name, "some value", i, translations[i].Value)
}

And as result in the file I see this strings:

msgid "Just one user online"
msgid_plural "Just one user online"
msgstr[0] "Il y a %d utilisateurs en ligne"

msgid "Just one user online"
msgid_plural "Just one user online"
msgstr[1] "Un seul utilisateur en ligne"

But it is not what I wanted, certainly. I could just concatenate some strings by myself, but we wanted to use this library and not work with bare hands.

Is this a bug, an improvement, a proposal or something else? Describe it.

Perhaps it's not a bug, just a lack of documentation. It would be great if the package were supplemented with similar examples.

@donseba
Copy link

donseba commented Jan 14, 2024

I was going through the specific function. IF your key.Name is the same, as it should, for single and plural, then it should work.

// Set the (N)th plural form for the given string
func (do *Domain) SetN(id, plural string, n int, str string) {
	// Get plural form _before_ lock down
	pluralForm := do.pluralForm(n)

	do.trMutex.Lock()
	do.pluralMutex.Lock()
	defer do.trMutex.Unlock()
	defer do.pluralMutex.Unlock()

	if trans, ok := do.translations[id]; ok {
		trans.SetN(pluralForm, str)
	} else {
		trans = NewTranslation()
		trans.ID = id
		trans.PluralID = plural
		trans.SetN(pluralForm, str)
		do.translations[str] = trans
	}
}

See line if trans, ok := do.translations[id]; ok {

@donseba
Copy link

donseba commented Feb 3, 2024

@kuzminT , I have found the issue .. in the snippet above you see do.translations[str] = trans , this should be do.translations[id] = trans

I have forked this repo since it is not active at the moment https://github.com/donseba/gotext

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