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

Feat/i18next language provider #96

Merged
merged 11 commits into from
Aug 28, 2024

Conversation

shamoilattaar-wednesday
Copy link
Collaborator

@shamoilattaar-wednesday shamoilattaar-wednesday commented Aug 23, 2024

Ticket Link


Related Links


Description


Steps to Reproduce / Test


GIF's


Summary by CodeRabbit

  • New Features

    • Transitioned the app's internationalization from Redux-based management to a simplified context-based approach using react-i18next.
    • Enhanced i18n setup with asynchronous language detection and improved translation handling.
    • Introduced a new utility function for conditional value selection to improve code readability.
  • Bug Fixes

    • Updated tests to ensure compatibility with the new i18next library, enhancing reliability.
  • Documentation

    • Updated comments and structures in various files to reflect changes in internationalization strategy.
  • Chores

    • Added new dependencies for i18next and related libraries to improve internationalization support.

Copy link

coderabbitai bot commented Aug 23, 2024

Walkthrough

The changes reflect a comprehensive overhaul of the application's internationalization framework, moving from react-intl to i18next and react-i18next. This transition includes necessary updates across multiple components and configurations to accommodate the new libraries. Additionally, the application has shifted away from Redux, adopting a simpler context-based architecture for state management, thereby streamlining translation handling and overall application structure.

Changes

Files Change Summary
app/app.js Restructured App component, removed Redux imports, integrated I18nextProvider for internationalization.
app/components/atoms/.../tests/index.test.js Updated tests across multiple components to replace renderWithIntl with renderWithI18next.
app/components/atoms/LanguageProvider/index.js Simplified to use useTranslation hook, removed Redux integration.
app/components/atoms/T/index.js Refactored to use useTranslation instead of injectIntl.
app/i18n.js Enhanced internationalization setup with i18next, added language detection and resources.
app/i18n.test.js Updated tests to focus on i18next configuration.
app/scenes/ExampleScreen/index.js Removed injectIntl from export, indicating a shift in internationalization handling.
app/utils/i18nextTestUtils.js, app/utils/testUtils.js Introduced new utility files for i18next, replaced renderWithIntl with renderWithI18next.
app/translations/en.json Updated string interpolation syntax from {username} to {{username}}.
package.json Added new dependencies: expo-crypto, i18next, react-i18next, and recoil.
setupTests.js Introduced mock implementations for i18next and react-i18next.
webpack.config.js Created new Webpack config for Expo applications.
ios/reactnativetemplatews.xcodeproj/project.pbxproj Updated build files and phases, added a new bridging header.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant I18nextProvider
    participant LanguageProvider

    User->>App: Launch Application
    App->>I18nextProvider: Initialize Internationalization
    I18nextProvider-->>App: Provide Translation Context
    App->>LanguageProvider: Render Language Context
    LanguageProvider-->>App: Pass Children with Translations
Loading

🐇
In a world where translations flutter,
The rabbit hops, no need to stutter!
From Redux we leap, to i18next bright,
With messages clear, oh what a delight!
Hopping through code, with a joyful cheer,
Every language welcomed, let’s spread the good cheer!
🌈


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@shamoilattaar-wednesday shamoilattaar-wednesday changed the title Feat/i18next languarge provider Feat/i18next language provider Aug 23, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ca2ba1d and 4ec5e95.

Files ignored due to path filters (5)
  • app/components/molecules/CharacterWithQuote/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • app/components/organisms/SimpsonsLoveWednesday/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • app/scenes/ExampleScreen/tests/__snapshots__/index.test.js.snap is excluded by !**/*.snap
  • ios/Podfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (22)
  • app/app.js (1 hunks)
  • app/components/atoms/Container/tests/index.test.js (1 hunks)
  • app/components/atoms/LanguageProvider/index.js (1 hunks)
  • app/components/atoms/LanguageProvider/tests/index.test.js (1 hunks)
  • app/components/atoms/T/index.js (2 hunks)
  • app/components/atoms/T/tests/index.test.js (1 hunks)
  • app/components/molecules/CharacterWithQuote/tests/index.test.js (2 hunks)
  • app/components/molecules/LogoWithInstructions/tests/index.test.js (1 hunks)
  • app/components/organisms/SimpsonsLoveWednesday/tests/index.test.js (3 hunks)
  • app/i18n.js (2 hunks)
  • app/i18n.test.js (1 hunks)
  • app/scenes/ExampleScreen/index.js (1 hunks)
  • app/scenes/RootScreen/index.js (2 hunks)
  • app/scenes/RootScreen/tests/index.test.js (1 hunks)
  • app/scenes/SplashScreen/tests/index.test.js (1 hunks)
  • app/translations/en.json (1 hunks)
  • app/utils/i18nextTestUtils.js (1 hunks)
  • app/utils/testUtils.js (1 hunks)
  • ios/reactnativetemplatews.xcodeproj/project.pbxproj (7 hunks)
  • package.json (3 hunks)
  • setupTests.js (1 hunks)
  • webpack.config.js (1 hunks)
Files skipped from review due to trivial changes (3)
  • app/components/atoms/Container/tests/index.test.js
  • app/components/atoms/LanguageProvider/tests/index.test.js
  • app/scenes/RootScreen/index.js
Additional context used
Biome
app/scenes/RootScreen/tests/index.test.js

[error] 9-10: Do not export from a test file.

(lint/suspicious/noExportsInTest)

Additional comments not posted (57)
app/translations/en.json (2)

2-2: LGTM!

The change to double curly braces for the username placeholder is correct and compatible with i18next.

The code changes are approved.


6-6: LGTM!

The change to double curly braces for the username placeholder is correct and compatible with i18next.

The code changes are approved.

webpack.config.js (3)

1-5: LGTM!

The import of createExpoWebpackConfigAsync and the definition of the module.exports function are correct.

The code changes are approved.


6-8: LGTM!

The modification to config.resolve.fallback to include a fallback for crypto using expo-crypto is correct.

The code changes are approved.


9-10: LGTM!

The return statement correctly returns the modified webpack configuration.

The code changes are approved.

app/app.js (2)

2-5: LGTM!

The imports of I18nextProvider, LanguageProvider, and i18n are correct and necessary for the integration of i18next.

The code changes are approved.


9-13: LGTM!

The wrapping of the App component with I18nextProvider and LanguageProvider is correct and necessary for providing internationalization support.

The code changes are approved.

app/components/atoms/T/tests/index.test.js (2)

7-7: LGTM!

The import statement has been correctly updated to use renderWithI18next.

The code changes are approved.


12-12: LGTM!

The rendering methods in the test cases have been correctly updated to use renderWithI18next.

The code changes are approved.

Also applies to: 17-17

app/scenes/SplashScreen/tests/index.test.js (2)

7-7: LGTM!

The import statement has been correctly updated to use renderWithI18next.

The code changes are approved.


12-12: LGTM!

The rendering methods in the test cases have been correctly updated to use renderWithI18next.

The code changes are approved.

Also applies to: 17-17

app/components/atoms/T/index.js (4)

11-11: LGTM!

The import statement has been correctly updated to use useTranslation from react-i18next.

The code changes are approved.


13-14: LGTM!

The T component has been correctly refactored to use the t function from useTranslation.

The code changes are approved.


16-18: LGTM!

The T component's return statement has been correctly updated to use the t function for translations.

The code changes are approved.


33-33: LGTM!

The export statement has been correctly simplified to directly export T.

The code changes are approved.

app/components/molecules/LogoWithInstructions/tests/index.test.js (2)

15-16: LGTM!

The function is correctly implemented and the change to use renderWithI18next is consistent with the PR objectives.

The code changes are approved.


20-22: LGTM!

The function is correctly implemented and the change to use renderWithI18next is consistent with the PR objectives.

The code changes are approved.

app/components/atoms/LanguageProvider/index.js (1)

3-23: LGTM!

The function is correctly implemented and the changes are consistent with the PR objectives. The removal of Redux-related code simplifies the component and enhances readability and maintainability.

The code changes are approved.

app/utils/testUtils.js (3)

14-15: LGTM!

The function is correctly implemented and the changes are consistent with the PR objectives.

The code changes are approved.


21-23: LGTM!

The function is correctly implemented and the changes are consistent with the PR objectives.

The code changes are approved.


Line range hint 27-27: LGTM!

The function is correctly implemented.

The code changes are approved.

app/scenes/RootScreen/tests/index.test.js (3)

8-8: LGTM!

The import statement has been correctly updated to use renderWithI18next.

The code changes are approved.


14-16: LGTM!

The test case has been correctly updated to use renderWithI18next.

The code changes are approved.


22-22: LGTM!

The test cases have been correctly updated to use renderWithI18next.

The code changes are approved.

Also applies to: 28-30

app/components/molecules/CharacterWithQuote/tests/index.test.js (3)

11-11: LGTM!

The import statement has been correctly updated to use renderWithI18next.

The code changes are approved.


16-16: LGTM!

The test case has been correctly updated to use renderWithI18next.

The code changes are approved.


29-32: LGTM!

The test case has been correctly updated to use renderWithI18next, and the expected text has been updated to 'wednesday_lover'.

The code changes are approved.

app/utils/i18nextTestUtils.js (4)

1-2: LGTM!

The import statements are necessary for setting up i18next.

The code changes are approved.


3-12: LGTM!

The comment block is informative and provides necessary context for the file.

The code changes are approved.


19-25: LGTM!

The language detector object is correctly implemented.

The code changes are approved.


27-41: LGTM!

The i18next initialization is correctly implemented with the language detector and initReactI18next.

The code changes are approved.

app/components/organisms/SimpsonsLoveWednesday/tests/index.test.js (3)

14-15: LGTM!

The test case is correctly updated to use renderWithI18next.

The code changes are approved.


29-31: LGTM!

The test case is correctly updated to use renderWithI18next.

The code changes are approved.


45-49: Verify the change in expectation.

The test case is correctly updated to use renderWithI18next. However, the expectation has been modified to check for a different string, wednesday_lover, instead of the previous dynamic text based on the props.user.character. Please verify if this change is intentional and aligns with the component's expected behavior.

app/i18n.js (4)

1-2: LGTM!

The import statements are correctly added.

The code changes are approved.


26-32: LGTM!

The languageDetector object is correctly implemented.

The code changes are approved.


50-50: LGTM!

The export statement is correctly added.

The code changes are approved.


Line range hint 52-60: LGTM!

The formatTranslationMessages function is correctly implemented.

The code changes are approved.

app/scenes/ExampleScreen/index.js (1)

92-92: Verify the impact of removing injectIntl.

The removal of injectIntl HOC from the export statement indicates a shift in how internationalization is handled within the component. Ensure that all functionalities relying on internationalization are still working as expected.

app/i18n.test.js (2)

1-28: Verify the impact of commenting out the previous mock implementation.

Commenting out the previous mock implementation for translation messages indicates a shift away from testing the formatTranslationMessages function directly. Ensure that the test coverage for translation message formatting is still adequate.


30-88: LGTM!

The new tests ensure that i18next is correctly configured and operational within the application context. The tests check for the presence of a language detector, initialization parameters, and language detection functionality.

package.json (4)

58-58: Verify the secure usage of expo-crypto.

The addition of expo-crypto suggests an intent to incorporate cryptographic functionalities within the Expo framework. Ensure that the usage of this library is secure and follows best practices.


63-63: Verify the integration of i18next.

The addition of i18next indicates a focus on internationalization, allowing the application to support multiple languages more effectively. Ensure that the integration of this library is correctly configured and tested.


72-72: Verify the integration of react-i18next.

The addition of react-i18next complements i18next by integrating it with React, streamlining the process of managing translations in React components. Ensure that the integration of this library is correctly configured and tested.


83-83: Verify the integration of recoil.

The addition of recoil introduces a state management solution, which could improve the handling of application state in a more efficient and scalable manner. Ensure that the integration of this library is correctly configured and tested.

ios/reactnativetemplatews.xcodeproj/project.pbxproj (12)

13-13: LGTM!

The reference to noop-file.swift has been correctly updated.

The code changes are approved.


27-27: LGTM!

The addition of the bridging header file reactnativetemplatews-Bridging-Header.h is correctly implemented.

The code changes are approved.


31-31: LGTM!

The reference to noop-file.swift has been correctly updated.

The code changes are approved.


60-60: LGTM!

The reference to noop-file.swift has been correctly updated.

The code changes are approved.


61-61: LGTM!

The addition of the bridging header file reactnativetemplatews-Bridging-Header.h is correctly implemented.

The code changes are approved.


246-246: LGTM!

The build phase [Expo] Configure project has been correctly renamed to [CP] Copy Pods Resources.

The code changes are approved.


252-257: LGTM!

The input paths for the [CP] Copy Pods Resources build phase have been correctly updated.

The code changes are approved.


259-259: LGTM!

The name of the build phase has been correctly updated.

The code changes are approved.


261-265: LGTM!

The output paths for the [CP] Copy Pods Resources build phase have been correctly updated.

The code changes are approved.


269-270: LGTM!

The shell script for the [CP] Copy Pods Resources build phase has been correctly updated.

The code changes are approved.


272-272: LGTM!

The build phase [CP] Embed Pods Frameworks has been correctly renamed.

The code changes are approved.


319-319: LGTM!

The reference to noop-file.swift has been correctly updated.

The code changes are approved.

setupTests.js Show resolved Hide resolved
setupTests.js Show resolved Hide resolved
app/i18n.js Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ec5e95 and 2e90e48.

Files selected for processing (1)
  • app/app.js (1 hunks)
Additional comments not posted (3)
app/app.js (3)

2-10: LGTM!

The imports are correctly added and necessary for the new structure.

The code changes are approved.


12-20: Verify the continued use of Redux.

The presence of Redux-related code indicates that Redux is still being used for state management, contrary to the AI-generated summary suggesting its removal. Please confirm if Redux is still intended to be used.


15-19: LGTM!

The App component is correctly structured to integrate the I18nextProvider for internationalization.

The code changes are approved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2e90e48 and a48c212.

Files selected for processing (1)
  • app/i18n.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/i18n.js

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a48c212 and 4b79b67.

Files ignored due to path filters (2)
  • ios/Podfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (3)
  • .eslintignore (1 hunks)
  • ios/reactnativetemplatews.xcodeproj/project.pbxproj (6 hunks)
  • package.json (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • ios/reactnativetemplatews.xcodeproj/project.pbxproj
  • package.json
Additional comments not posted (8)
.eslintignore (8)

6-6: LGTM!

Adding .eslintrc.js to the ignore list is a good practice to avoid linting the ESLint configuration file itself.


7-7: LGTM!

Adding the e2e directory to the ignore list is appropriate if end-to-end tests are not relevant to the linting process.


8-8: LGTM!

Adding the metrics directory to the ignore list is appropriate if metrics files are not relevant to the linting process.


9-9: LGTM!

Adding jest.setup.js to the ignore list is appropriate if the Jest setup file is not relevant to the linting process.


10-10: LGTM!

Adding babel.config.js to the ignore list is appropriate if the Babel configuration file is not relevant to the linting process.


11-11: LGTM!

Adding the reports directory to the ignore list is appropriate if report files are not relevant to the linting process.


12-12: LGTM!

Adding report.json to the ignore list is appropriate if the report file is not relevant to the linting process.


13-13: LGTM!

Adding **/tests/*.test.js to the ignore list is appropriate if test files are not relevant to the linting process.


import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/lib/integration/react';
Copy link
Contributor

Choose a reason for hiding this comment

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

can we please fix the import order

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

placed as a placeholder for the other components that still are dependent on redux will be removed altogether

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b79b67 and 5e0bae0.

Files selected for processing (2)
  • app/components/atoms/T/index.js (2 hunks)
  • app/utils/common.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • app/utils/common.js
Files skipped from review as they are similar to previous changes (1)
  • app/components/atoms/T/index.js

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.

2 participants