Skip to content

fix: gb->en #2246

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

Closed
wants to merge 3 commits into from
Closed

fix: gb->en #2246

wants to merge 3 commits into from

Conversation

ajhollid
Copy link
Collaborator

@ajhollid ajhollid commented May 11, 2025

This PR sets the default language to en instead of gb

  • Remove conversion of en to gb from workflow script
  • Set en as default language
  • Rename gb.json to en.json
  • Update language selector to select gb flag for en as there is no en flag

Summary by CodeRabbit

  • Bug Fixes
    • Updated the flag icon in the language selector to display the Great Britain flag for English instead of an incorrect flag.
    • Changed the default fallback language for translations to English.

Copy link

coderabbitai bot commented May 11, 2025

Walkthrough

The changes update the language selector to display the Great Britain flag for English by mapping "en" to "gb" in the CSS class, and adjust the i18n fallback language from "gb" to "en". Additionally, a translation download script was reformatted for style consistency and simplified filename handling. No exported or public entities were modified.

Changes

File(s) Change Summary
client/src/Components/LanguageSelector.jsx Updated flag icon logic to map "en" to "gb" for English, ensuring the correct flag is shown.
client/src/Utils/i18n.js Changed i18n fallback language from "gb" to "en".
.github/scripts/download-translations.js Reformatted code for style consistency, removed conditional English filename, no logic change.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LanguageSelector
    participant FlagIcon

    User->>LanguageSelector: Selects a language
    LanguageSelector->>FlagIcon: Map language code ("en" → "gb", else unchanged)
    FlagIcon-->>LanguageSelector: Returns appropriate flag class
    LanguageSelector-->>User: Displays correct flag in UI
Loading

And remember, switching from "gb" to "en" as a fallback means Americans and Canadians can finally agree on how to spell "color"—or at least agree to disagree! (Though Canadians might still insist it’s “colour,” eh?)

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72d03f7 and a3a0bdf.

📒 Files selected for processing (1)
  • .github/scripts/download-translations.js (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .github/scripts/download-translations.js
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

@llamapreview llamapreview bot left a comment

Choose a reason for hiding this comment

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

Auto Pull Request Review from LlamaPReview

1. Overview

1.1 Core Changes

  • Primary purpose and scope: This PR aims to standardize the application's primary English localization from UK English ('gb') to generic International English ('en').
  • Key components modified:
    • client/src/Components/LanguageSelector.jsx: Updated to display the GB flag for the 'en' language option.
    • client/src/Utils/i18n.js: Default language changed from 'gb' to 'en'.
    • client/src/locales/gb.json: Renamed to client/src/locales/en.json.
  • Cross-component impacts: This change affects all parts of the application that utilize i18next for translations. It also impacts how user language preferences stored in localStorage are handled.
  • Business value alignment: Standardizes localization to international English, potentially improving consistency and user experience for a global audience. Simplifies the localization structure by removing an artificial 'gb' to 'en' distinction that was previously in place.

1.2 Technical Architecture

  • System design modifications: The default language initialization logic within the i18n setup has been changed. The way language codes are mapped to display flags in the UI has also been adjusted.
  • Component interaction changes:
    • LanguageSelector.jsx now contains specific logic to map the 'en' language code to a 'gb' flag code for display purposes.
    • i18n.js now initializes with 'en' as the primaryLanguage.
  • Integration points impact: Any existing user preferences stored with 'gb' as the language code will need to be migrated to 'en' to ensure a seamless transition. Backend systems or analytics that might have been tracking language preferences using 'gb' might also need to be aware of this change.
  • Dependency changes and implications: No new dependencies are added. The configuration of the existing i18next library is modified.

2. Critical Findings

2.1 Must Fix (P0🔴)

Issue: Debug console.log statement in i18n.js.

  • Analysis Confidence: High
  • Impact: Exposes internal i18next state (i18n.languages) to the browser console in production. This is unprofessional, can clutter the console, and offers no value to end-users.
  • Resolution: Remove the line console.log(i18n.languages); from client/src/Utils/i18n.js.

Issue: No migration path for existing users with 'gb' language preference.

  • Analysis Confidence: High
  • Impact: Users who previously selected 'gb' as their language will have their localStorage value for i18nextLng as 'gb'. Upon this update, if 'gb' is no longer a recognized or primary language, they might revert to a default language or encounter issues with translations. This leads to a poor user experience.
  • Resolution: Implement logic in client/src/Utils/i18n.js to check localStorage for an existing 'gb' preference. If found, it should be programmatically changed to 'en', and localStorage should be updated accordingly to ensure persistence of the migrated preference. (See suggested code in Technical Analysis 3.1 for i18n.js).

2.2 Should Fix (P1🟡)

Issue: Hardcoded flag mapping in LanguageSelector.jsx.

  • Analysis Confidence: High
  • Impact: The logic lang === "en" ? "gb" : lang directly embeds the mapping for the English flag. If other languages require similar specific flag mappings in the future, or if this mapping needs to change, it requires modifying this direct conditional logic, making it less maintainable and scalable.
  • Suggested Solution: Centralize flag mappings into a configuration object (e.g., const FLAG_MAPPINGS = { en: 'gb' };) and use this object to determine the flag code. This makes it easier to manage and extend such mappings.

Issue: Potential for remaining hardcoded 'gb' references in the codebase.

  • Analysis Confidence: Medium
  • Impact: If any components or utility functions still use 'gb' directly in translation keys (e.g., t('gb.someKey') or <Trans i18nKey="gb.someKey">), these translations will break after gb.json is removed and 'gb' is no longer a primary language code.
  • Suggested Solution: Conduct a thorough search across the client-side codebase for any hardcoded instances of "gb." or similar patterns used with i18next translation functions or components. Replace these with "en." to align with the new primary language code.

2.3 Consider (P2🟢)

Area: Explicit fallback language configuration in i18n.js.

  • Analysis Confidence: Medium
  • Improvement Opportunity: While i18next might have default fallback behavior, explicitly setting fallbackLng: 'en' in the i18n.init() options ensures that if a translation key is missing for a selected language (if other languages are supported), it will gracefully degrade to English. This improves robustness.

Area: Locale validation in LanguageSelector.jsx.

  • Analysis Confidence: Medium
  • Improvement Opportunity: If the languages array passed to LanguageSelector.jsx could potentially contain unsupported language codes, filtering this array against a predefined list of validLanguages (e.g., ['en', 'fr', 'de']) before mapping would make the component more robust against unexpected data.

2.4 Summary of Action Items

  • P0 (Immediate Fixes):
    1. Remove the console.log(i18n.languages); statement from client/src/Utils/i18n.js.
    2. Implement migration logic in client/src/Utils/i18n.js to convert existing user preferences from 'gb' to 'en' in localStorage.
  • P1 (Recommended Before Merge):
    1. Refactor LanguageSelector.jsx to use a centralized mapping for language-to-flag codes.
    2. Audit the codebase for any remaining hardcoded 'gb' translation key prefixes and update them to 'en'.
  • P2 (Consider for Future Improvement):
    1. Explicitly configure fallbackLng: 'en' in i18n.js.
    2. Add locale validation in LanguageSelector.jsx if applicable.

3. Technical Analysis

3.1 Code Logic Analysis

📁 client/src/Utils/i18n.js - Module Scope (Language Initialization)

  • Submitted PR Code:
    - const primaryLanguage = "gb";
    + console.log(i18n.languages); // Added debug log
    + const primaryLanguage = "en"; // Changed primary language
  • Analysis:
    • Current logic: The primaryLanguage constant is changed from "gb" to "en". A console.log statement has been added, presumably for debugging, which outputs the languages known to i18next.
    • Potential issues:
      1. The console.log is a debug artifact and should not be in production code.
      2. This change does not account for existing users who might have 'gb' stored as their preferred language in localStorage (typically under the key i18nextLng). These users might lose their language setting or see unexpected behavior.
    • Edge cases: Users with localStorage.getItem('i18nextLng') === 'gb'.
    • Business logic considerations: The default language for all users and the system should now be 'en'.
  • LlamaPReview Suggested Improvements:
    import i18n from "i18next";
    import { initReactI18next } from "react-i18next";
    import { setLanguage } from "../Features/UI/uiSlice";
    import store from "../store";

    // const primaryLanguage = "gb"; // Old value

    // console.log(i18n.languages); // CRITICAL: Remove this debug statement

    let effectivePrimaryLanguage = "en"; // Default to 'en'
    const storedLang = localStorage.getItem('i18nextLng');

    if (storedLang === 'gb') {
      localStorage.setItem('i18nextLng', 'en'); // Migrate stored preference to 'en'
      effectivePrimaryLanguage = 'en'; // Ensure 'en' is used
    } else if (storedLang && resources[storedLang]) { // Check if storedLang is valid and has resources
      effectivePrimaryLanguage = storedLang;
    }
    // If no storedLang or invalid storedLang, it defaults to 'en' as defined above

    const primaryLanguage = effectivePrimaryLanguage;

    const translations = import.meta.glob("../locales/*.json", { eager: true });

    const resources = {};
    Object.keys(translations).forEach((path) => {
    	const langCode = path.match(/\/([^/]+)\.json$/)[1];
    	resources[langCode] = {
    		translation: translations[path].default || translations[path],
    	};
    });
    // ... rest of the i18n initialization
  • Improvement rationale:
    • Technical benefits: Removes the debug console.log. Implements a migration strategy for users with an existing 'gb' preference by updating their localStorage and ensuring 'en' is used. It also respects other valid stored language preferences.
    • Business value: Ensures a smoother transition for existing users, maintaining their language preference (by mapping 'gb' to 'en') and preventing a negative user experience.
    • Risk assessment: Low risk. This change directly addresses a P0 issue and improves robustness.

📁 client/src/Components/LanguageSelector.jsx - Anonymous function within map

  • Submitted PR Code:
    			{languages.map((lang) => {
    -				const flag = lang ? `fi fi-${lang}` : null;
    -
    +				const parsedLang = lang === "en" ? "gb" : lang; // Map 'en' to 'gb' for flag
    +				const flag = parsedLang ? `fi fi-${parsedLang}` : null;
    				return (
    					<MenuItem
    						key={lang}
  • Analysis:
    • Current logic: The code now checks if the lang is 'en'. If it is, parsedLang is set to 'gb'; otherwise, parsedLang takes the value of lang. This parsedLang is then used to construct the CSS class for the flag icon (e.g., fi fi-gb). This is done because the application uses 'en' as the language code but wants to display the Great Britain (GB) flag.
    • Potential issues: This direct, hardcoded mapping lang === "en" ? "gb" : lang is not very maintainable. If other languages need special flag representations or if the 'en' to 'gb' mapping changes, this specific line of code needs to be found and modified.
    • Edge cases: Assumes that for all other languages, the language code directly corresponds to a valid flag icon code in the fi fi- set.
  • LlamaPReview Suggested Improvements:
    // Consider defining this at a higher scope or in a constants file if used elsewhere
    const LANGUAGE_TO_FLAG_CODE_MAPPING = {
      en: 'gb',
      // Example: es: 'es', // Default, could be omitted if lang code matches flag code
      // Example: ca: 'es-ca', // If 'ca' (Catalan) should use a specific Spanish regional flag
    };

    // ... inside the component
    			{languages.map((lang) => {
    				// const parsedLang = lang === "en" ? "gb" : lang; // Old hardcoded way
    				const flagCodeToShow = LANGUAGE_TO_FLAG_CODE_MAPPING[lang] || lang; // Use mapping, or lang itself if no specific mapping
    				const flag = flagCodeToShow ? `fi fi-${flagCodeToShow}` : null;

    				return (
    					<MenuItem
    						key={lang}
    						value={lang}
    						// ... rest of MenuItem props
    					/>
    				);
    			})}
  • Improvement rationale:
    • Technical benefits: Improves maintainability and readability. The special mapping logic is centralized in the LANGUAGE_TO_FLAG_CODE_MAPPING object. If more such mappings are needed, they can be added to this object without changing the core logic of the map function.
    • Business value: Makes the system more adaptable to future changes in flag display requirements or additions of new languages with specific flag needs.
    • Risk assessment: Very low risk. This is a refactoring for better code structure and maintainability.

3.2 Key Quality Aspects

  • Testing strategy and coverage:
    • Manual testing should verify:
      1. New users see 'en' (with GB flag) as default.
      2. Existing users with 'gb' preference are seamlessly migrated to 'en' (with GB flag) and their localStorage is updated.
      3. Existing users with other language preferences (if any) retain their settings.
      4. Language selector correctly displays flags and allows changing languages.
    • Consider adding automated tests for the localStorage migration logic if not already covered.
  • Documentation needs:
    • Internal documentation regarding localization should be updated to reflect that 'en' is the standard code for English.
    • If there's user-facing documentation about language selection, it might need a note if the GB flag for "English" could cause confusion, though this is a minor point.

4. Overall Evaluation

  • Technical assessment: The PR successfully changes the primary language code from 'gb' to 'en' and renames the locale file. However, it introduces a critical P0 issue (debug console.log) and misses another critical P0 consideration (migration for existing 'gb' users). The flag handling in LanguageSelector.jsx is functional but could be more maintainable.
  • Business impact: Positive in the long term due to standardization to 'en'. However, without addressing the P0 issues, there's a risk of negative impact on user experience for existing users and a slight lapse in production code quality.
  • Risk evaluation: Currently Medium due to the P0 findings. If P0s are addressed, the risk becomes Low.
  • Notable positive aspects and good practices: The core goal of standardizing to 'en' is a good practice for internationalization. Renaming the locale file (gb.json to en.json) is the correct approach.
  • Implementation quality: Fair. The core change is straightforward, but critical oversights need correction.
  • Final recommendation: Request Changes
    • The P0 issues (debug log removal and user preference migration) must be addressed before this PR can be merged.
    • The P1 suggestions (centralized flag mapping and audit for 'gb' references) are highly recommended for improved maintainability and robustness.

💡 LlamaPReview Community
Have feedback on this AI Code review tool? Join our GitHub Discussions to share your thoughts and help shape the future of LlamaPReview.

@gorkem-bwl gorkem-bwl added this to the 2.1 (Ship of Theseus) milestone May 13, 2025
@Cihatata
Copy link
Collaborator

we should update upload-poeditor.yml and poeditor-sync.yml

@gorkem-bwl gorkem-bwl modified the milestones: 2.1 (Ship of Theseus), 3.0 May 27, 2025
@ajhollid ajhollid closed this May 28, 2025
@ajhollid ajhollid deleted the fix/gb-to-en branch May 28, 2025 17:21
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