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

Could we use formatting functions in the nesting 't' function? #1419

Merged
merged 2 commits into from
Apr 8, 2020

Conversation

brett-js
Copy link
Contributor

@brett-js brett-js commented Apr 3, 2020

For example:

{
    "key1": "The following text is uppercased: $t(key2, uppercase)",
    "key2": "some text"
}
i18next.t('key1');
// -> "The following text is uppercased: SOME TEXT"

If uppercase is defined as:

i18next.init({
    interpolation: {
        format: function(value, format, lng) {
            if (format === 'uppercase') return value.toUpperCase();
            return value;
        }
    }
});

@coveralls
Copy link

coveralls commented Apr 3, 2020

Coverage Status

Coverage increased (+0.03%) to 93.528% when pulling 4f0c979 on brett-js:master into 99e24d3 on i18next:master.

@jamuhl
Copy link
Member

jamuhl commented Apr 3, 2020

If possible would you be able to add a test to avoid future regression?

@brett-js
Copy link
Contributor Author

brett-js commented Apr 6, 2020

Hey @jamuhl , sorry about that. I'll amend the pull request :)

@brett-js
Copy link
Contributor Author

brett-js commented Apr 7, 2020

@jamuhl Just finished adding in some tests. Do let me know if you'd like further changes or have other feedback. I have plenty of spare time now that my country is in lockdown.

@jamuhl jamuhl merged commit d8f0a88 into i18next:master Apr 8, 2020
@jamuhl
Copy link
Member

jamuhl commented Apr 8, 2020

thank you...landed in i18next@19.4.0

@Arkellys
Copy link

What about nested translations with params?

{
    "key1": "Example: $t(key2, {\"count\": 0 }, uppercase)",
    "key2": "element",
    "key2_plural": "elements"
}

Could this be possible?

@adrai
Copy link
Member

adrai commented Jun 29, 2021

What about nested translations with params?


{

    "key1": "Example: $t(key2, {\"count\": 0 }, uppercase)",

    "key2": "element",

    "key2_plural": "elements"

}

Could this be possible?

Based on the tests, it should work: https://github.com/i18next/i18next/blob/master/test/i18next.interpolation.nesting.spec.js but only without formatting function: "Example: $t(key2, {\"count\": 0 })",

@Arkellys
Copy link

@adrai Yes, I was wondering if there was a way to make it work with formatting.

@adrai
Copy link
Member

adrai commented Jun 29, 2021

@adrai Yes, I was wondering if there was a way to make it work with formatting.

no

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.

None yet

5 participants