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

Support for empty strings in translation files. #261

Merged
merged 1 commit into from
Oct 23, 2019

Conversation

emmerich
Copy link

@emmerich emmerich commented Aug 3, 2016

I currently have a use-case where I need to have an empty string in my translation file. Currently, i18n-node will replace this translation with the key, as it thinks that the translation does not exist. Here's an example:

en.json
{
    "AddToGroup.1": "Add to",
    "AddToGroup.2": "group"
}

fr.json
{
    "AddToGroup.1": "Ajouter au groupe",
    "AddToGroup.2": ""
}

Used like so;

__('AddToGroup.1') + '<strong>' + groupName + '</strong>' + __('AddToGroup.2')

Currently, this is output like so (with group name X):
English:
Add to <strong>X</strong> group

French:
Ajouter au groupe <strong>X</strong> AddToGroup.2

because i18n-node will replace the empty string for AddToGroup.2 in French with the key AddToGroup.2.

This pull request fixes that by only replacing with the key if the translation key does not exist, rather than being empty string (was a basic falsey check where it should've been a check for null/undefined).

Also added some tests for this use case.

@coveralls
Copy link

coveralls commented Aug 3, 2016

Coverage Status

Coverage remained the same at 97.908% when pulling 4c1849a on emmerich:master into 2a96f26 on mashpie:master.

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 this pull request may close these issues.

3 participants