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

fix: react-i18next, added better support for namespace overrides, corrected e2e-tests #871

Merged
merged 8 commits into from
Apr 24, 2023

Conversation

Swiftwork
Copy link
Contributor

@Swiftwork Swiftwork commented Dec 20, 2022

This pull request clears up the issues introduced by #735 and improves upon the react-i18next framework.

  1. Corrected broken import references referring to './react'
  2. Updated broken fluent-vue-cli dependency
  3. Removed obsolete package-lock.json as project uses yarn
  4. Actually added previously not included react-i18next to frameworks list and configuration
  5. Lifted useTranslate scopes which is react specific from i18next to react-i18next
  6. Added support for t('key', { ns: 'namespace' }) and <Trans i18nKey="key" ns="namespace" />
  7. Corrected e2e tests and added new ones for the new scopes feature

The changes have also been tested on my project and I can confirm it is working. However, another set of eyes would be appreciated so that we don't have a repeat of #735.

Resolves #677, resolves #688, resolves #823, resolves #786

@Swiftwork
Copy link
Contributor Author

Swiftwork commented Dec 20, 2022

@beinarovic, @antfu please give this a look

@Swiftwork
Copy link
Contributor Author

@anilkk could you take a look at this?

@auduongtuan
Copy link

auduongtuan commented Apr 8, 2023

any info on the review of this PR?

Co-authored-by: Michael Overmeyer <michael@overmeyer.io>
@kibertoad
Copy link
Collaborator

@movermeyer Would you say that this is a better fix than #873?

Copy link
Contributor

@movermeyer movermeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I've tested these changes myself locally.

src/frameworks/react-i18next.ts Outdated Show resolved Hide resolved
keypath,
]
}

rewriteKeys(key: string, source: RewriteKeySource, context: RewriteKeyContext = {}) {
const dotedKey = key.split(this.namespaceDelimitersRegex).join('.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, during i18n-ally.extract-text, keys with either : or / will fail to get here, since they will be caught by this call to keypathValidate.

This isn't necessarily a problem for this PR (it works for the other uses), but something that'll need to be fixed in the future in order to get things working 100% with react-i18n. (Just a note for myself really)

if (Global.namespaceEnabled) {
namespace = node?.meta?.namespace || namespace
if (namespace)
if (namespace && keypath.startsWith(namespace + delimiter))
return keypath.slice(namespace.length + 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Not this PR's fault]

Shouldn't this do the slice based on the length of the delimiter (for robustness). Can we assume that a delimiter will always be a single character?

(Just a note for myself really)

Co-authored-by: Michael Overmeyer <michael@overmeyer.io>
@movermeyer
Copy link
Contributor

@movermeyer Would you say that this is a better fix than #873?

While both solve the failing build problem, they otherwise solve different problems.

Once the build is working again, we can evaluate the other changes that #873 offers.

@kibertoad
Copy link
Collaborator

@Swiftwork Could you please fix the build and address the code comments? Then this will be merged

@movermeyer
Copy link
Contributor

@Swiftwork Could you please fix the build and address the code comments? Then this will be merged

I think getting the tests to pass is just a matter of:

yarn test:e2e:update
git add -u test/e2e/frameworks/react-i18next/basic.test.js.snap
git commit
git push

But I don't have the permissions to push to your branch

@Swiftwork
Copy link
Contributor Author

I have updated the snapshot. However, as it, unfortunately, was a while ago since I wrote the code and the PR, I can't remember the relevance of dottedKey, but I believe it was copied from existing code.

@kibertoad
Copy link
Collaborator

@Swiftwork tests are still failing

@Swiftwork
Copy link
Contributor Author

@kibertoad Correct me if I am wrong, but these test failures look unrelated to my code and seemingly have something to do with Vue.

@kibertoad
Copy link
Collaborator

@movermeyer Do you think test failures should be addressed in a separate PR?

@movermeyer
Copy link
Contributor

@movermeyer Do you think test failures should be addressed in a separate PR?

@kibertoad I agree, these test failures are independent of this PR. Let's merge this and deal with those failures separately.

@kibertoad kibertoad merged commit 6f61ef2 into lokalise:main Apr 24, 2023
0 of 3 checks passed
@kibertoad
Copy link
Collaborator

@Swiftwork thanks a lot for your contribution!

@Swiftwork Swiftwork deleted the fix/react-i18next-framework branch May 4, 2023 15:39
@auduongtuan
Copy link

It seems like the plural (_one, _other) still doesn't work 😂 or maybe I've missed some configurations...

@newza-fullmetal
Copy link

Same with plural v4 format with i18next v23.4.4 and react-i18next v13.1.2

huacnlee pushed a commit to huacnlee/i18n-ally that referenced this pull request Aug 28, 2023
…rected e2e-tests (lokalise#871)

Co-authored-by: Igor Savin <iselwin@gmail.com>
Co-authored-by: Michael Overmeyer <michael@overmeyer.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants