Skip to content

Support for empty strings in translation files.#261

Merged
mashpie merged 1 commit intomashpie:masterfrom
emmerich:master
Oct 23, 2019
Merged

Support for empty strings in translation files.#261
mashpie merged 1 commit intomashpie:masterfrom
emmerich:master

Conversation

@emmerich
Copy link
Copy Markdown

@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
Copy Markdown

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