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

ngettext replacement ? #1096

Closed
gunzino opened this issue Sep 4, 2018 · 9 comments
Closed

ngettext replacement ? #1096

gunzino opened this issue Sep 4, 2018 · 9 comments

Comments

@gunzino
Copy link

gunzino commented Sep 4, 2018

Hello,

Currently we hare using ngettext function in our PHP app. This function includes default values for both singular and plural strings.

If we use i18next in our JS app the programmer is able to specify only one version of the default string (which could be key or defaultValue property). Therefore, he has to add the plural version to the translation file manually. Using ngettext in PHP the app is fully functional without programmer touching the translation files.

I would like to ask if you plan to add some function that could be used to replace ngettext ?

Thnaks.

@jamuhl
Copy link
Member

jamuhl commented Sep 4, 2018

the save missing feature https://github.com/i18next/i18next/blob/master/src/Translator.js#L158 will already create the needed keys for both singular and plural - just it uses the same defaultValue...but i guess that is ok - as it's not the developers concern to get both singular and plural correct -> translators will/should review texts made by developers anyway.

So eg. using https://locize.com you will get all that out of the box - without having to handle the saveMissings on your backend

@jamuhl
Copy link
Member

jamuhl commented Sep 4, 2018

So is your need more related to defining defaultValues for all possible plural forms (depending on your source language)?

@gunzino
Copy link
Author

gunzino commented Sep 4, 2018

We are just used to that application is fully working with default english language with any newly feature added. Also we have some applications that are not going to be translated anytime soon but may be translated in the future. Therefore singular and plural value in english (or any other language with one plural form) is enough for the application to work - in this case not any translation files are needed. If we migrate to i18next we have to create english translation file and fill it with all the plurals. Also that file has to be manually managed by programmers if they add new feature.

@jamuhl
Copy link
Member

jamuhl commented Sep 4, 2018

ok i see...basically you would prefer the key to be the fallback (which works for i18next) but for plural cases you like to add the defaults.

we fallback either to default value or key here: https://github.com/i18next/i18next/blob/master/src/Translator.js#L121

when doing a translation lookup we return found or not found value here: https://github.com/i18next/i18next/blob/master/src/Translator.js#L278

we could add the needed pluralSuffix from here: https://github.com/i18next/i18next/blob/master/src/Translator.js#L254 to that return value

and than use that suffix (if exists = isAPlural) to check if there is some defaultValue_plural or depending on other language having multiple pluralforms defaultValue_[0|1|2|...]

Would that help?

@gunzino
Copy link
Author

gunzino commented Sep 4, 2018

Yeah definitely that would be great feature ;)

@jamuhl
Copy link
Member

jamuhl commented Sep 4, 2018

If you feel comfortable you might add a PR...else i will see what i can do...not to complicated...but currently limited on time.

@gunzino
Copy link
Author

gunzino commented Sep 5, 2018

I might try that today. Also in my opinion plural suffix is very 'inaccurate' feature. In many languages there are more suffixes (in my lanaguage too - Slovak), also in english (s, es).

@jamuhl
Copy link
Member

jamuhl commented Sep 5, 2018

yes...there are more suffixes for languages having multiple pluralforms - just checkout: https://www.i18next.com/translation-function/plurals#languages-with-multiple-plurals (below there is also a tool to lookup those suffixes - plus using locize it will do this automatically for target languages - so one thing less to think about.)

@jamuhl
Copy link
Member

jamuhl commented Sep 5, 2018

94173ea

@jamuhl jamuhl closed this as completed Sep 5, 2018
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