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

Add System Language Item #3161

Merged
merged 8 commits into from
Jan 25, 2025
Merged

Add System Language Item #3161

merged 8 commits into from
Jan 25, 2025

Conversation

Jack251970
Copy link
Contributor

Add support of system language item to help FL automatically select the system language as display language

image

  • Test already done
    • Change to "System" language
    • Switch Windows display language to English & Chinese
    • After switching the language, restart FL and the display language of FL changes

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhanced language handling capabilities in the Flow Launcher Core. The changes focus on improving internationalization support by adding a new method to retrieve system translations and modifying the language change mechanism. The updates include a new GetSystemTranslation method in the AvailableLanguages class and significant modifications to the Internationalization class to better manage system and default language settings.

Changes

File Change Summary
Flow.Launcher.Core/Resource/AvailableLanguages.cs Added GetSystemTranslation(string languageCode) method to return localized "System" translations.
Flow.Launcher.Core/Resource/Internationalization.cs - Updated ChangeLanguage method signature to private void ChangeLanguage(Language language, bool isSystem)
- Added private static string GetSystemLanguageCodeAtStartup() method
- Introduced DefaultLanguageCode constant
- Modified language loading logic to include system language.
Flow.Launcher.Infrastructure/Constant.cs Added constant public const string SystemLanguageCode = "system"; initialized to "system".
Flow.Launcher.Infrastructure/UserSettings/Settings.cs Updated language field initialization to use Constant.SystemLanguageCode instead of hardcoded "en".

Possibly related PRs

Suggested labels

kind/i18n

Poem

🐰 In the realm of code so bright,
Languages dance with pure delight,
System words now find their way,
Translations leap and softly play,
A linguistic rabbit's merry flight! 🌍


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>, 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.

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. (Beta)
  • @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
Contributor

@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

🧹 Nitpick comments (2)
Flow.Launcher.Core/Resource/Internationalization.cs (2)

181-184: Inserting system language at the top of the list
Prepending the system language in LoadAvailableLanguages ensures immediate visibility in the UI. As a possible improvement, consider whether sorting or grouping logic should be flexible, e.g., if other future “special” languages need to appear.


186-209: Implementing a straightforward system language resolution
By iterating through the available languages, this code finds a match or defaults to English. This is fine for a moderate list of languages. If performance or loading time becomes a concern in the future, a mapping/dictionary approach may be more optimal.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd3576d and 0ae3cfc.

📒 Files selected for processing (2)
  • Flow.Launcher.Core/Resource/AvailableLanguages.cs (1 hunks)
  • Flow.Launcher.Core/Resource/Internationalization.cs (5 hunks)
🔇 Additional comments (6)
Flow.Launcher.Core/Resource/Internationalization.cs (5)

21-22: Use of separate constants for system and default language is clear
Defining SystemLanguageCode and DefaultLanguageCode as constants clarifies the distinction between system language handling and the fallback language.


73-81: Good logic for detecting and handling the system language
This section correctly checks if the user-supplied languageCode is the special SystemLanguageCode and then resolves the actual system-based code. Ensure consistent usage throughout the codebase, particularly in places where languageCode might be compared with "System".


82-84: Calls the new internal overload appropriately
Directly mapping the resolved language code to your ChangeLanguage(Language, bool) overload maintains clarity. Good job.


102-102: Changing method signature to private might break external references
Previously, ChangeLanguage(Language language) looked publicly exposed. Confirm there is no external usage of the old signature. If it was only used internally, making the method private is fine. Otherwise, consider backward compatibility.


117-117: Settings now explicitly captures system language
Using a ternary operator here to store either "System" or the actual language code helps you persist the user’s intent. This ensures the system language remains recognized upon future application restarts.

Flow.Launcher.Core/Resource/AvailableLanguages.cs (1)

66-97: Method covering a broad set of languages for “System” translations
GetSystemTranslation switches across all supported languages, returning a localized string for “System.” This approach is straightforward. For scalability, you might eventually consider a resource-based solution or something that can be updated without code changes.

@Jack251970 Jack251970 requested a review from jjw24 January 5, 2025 12:51

This comment has been minimized.

Copy link

gitstream-cm bot commented Jan 6, 2025

🥷 Code experts: Yusyuriv

Yusyuriv has most 👩‍💻 activity in the files.
onesounds, jjw24 have most 🧠 knowledge in the files.

See details

Flow.Launcher.Core/Resource/AvailableLanguages.cs

Activity based on git-commit:

Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
onesounds: 6%
jjw24: 1%

Flow.Launcher.Core/Resource/Internationalization.cs

Activity based on git-commit:

Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG 1 additions & 0 deletions

Knowledge based on git-blame:
jjw24: 11%

Flow.Launcher.Infrastructure/Constant.cs

Activity based on git-commit:

Yusyuriv
JAN
DEC
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
jjw24: 41%
onesounds: 9%

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Activity based on git-commit:

Yusyuriv
JAN
DEC 5 additions & 3 deletions
NOV
OCT
SEP
AUG

Knowledge based on git-blame:
onesounds: 25%
jjw24: 3%

To learn more about /:\ gitStream - Visit our Docs

Copy link
Contributor

@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: 1

🧹 Nitpick comments (3)
Flow.Launcher.Infrastructure/Constant.cs (1)

56-56: Consider verifying or clarifying naming consistency.
While using "System" as the label may be acceptable, you might want to explicitly mark it as a system-reserved or system-based language code in comments or docstring. This ensures clarity in cases where "System" might clash with other usages in the codebase or third-party library references.

Flow.Launcher.Core/Resource/Internationalization.cs (2)

72-83: Consider adding error logging for system language resolution.

The system language handling logic is well-structured. However, consider adding error logging when the system language code resolution fails, to help with troubleshooting.

 if (languageCode == Constant.SystemLanguageCode)
 {
     languageCode = GetSystemLanguageCode();
+    Log.Debug($"|Internationalization.ChangeLanguage|Resolved system language to: {languageCode}");
     isSystem = true;
 }

185-208: Consider caching the system language code.

The implementation thoroughly checks different culture codes, but since the system language doesn't change frequently, consider caching the result to avoid repeated culture info lookups and string comparisons.

 private string GetSystemLanguageCode()
 {
+    // Cache the result as it rarely changes
+    if (_cachedSystemLanguageCode != null)
+        return _cachedSystemLanguageCode;
+
     var availableLanguages = AvailableLanguages.GetAvailableLanguages();
     
     // Retrieve the language identifiers for the current culture
     var currentCulture = CultureInfo.CurrentCulture;
     var twoLetterCode = currentCulture.TwoLetterISOLanguageName;
     var threeLetterCode = currentCulture.ThreeLetterISOLanguageName;
     var fullName = currentCulture.Name;

     // Try to find a match in the available languages list
     foreach (var language in availableLanguages)
     {
         var languageCode = language.LanguageCode;

         if (string.Equals(languageCode, twoLetterCode, StringComparison.OrdinalIgnoreCase) ||
             string.Equals(languageCode, threeLetterCode, StringComparison.OrdinalIgnoreCase) ||
             string.Equals(languageCode, fullName, StringComparison.OrdinalIgnoreCase))
         {
-            return languageCode;
+            _cachedSystemLanguageCode = languageCode;
+            return _cachedSystemLanguageCode;
         }
     }

-    return DefaultLanguageCode;
+    _cachedSystemLanguageCode = DefaultLanguageCode;
+    return _cachedSystemLanguageCode;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0ae3cfc and 6febbe7.

📒 Files selected for processing (3)
  • Flow.Launcher.Core/Resource/Internationalization.cs (5 hunks)
  • Flow.Launcher.Infrastructure/Constant.cs (1 hunks)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (4)
Flow.Launcher.Core/Resource/Internationalization.cs (4)

21-21: LGTM! Good use of a constant for the default language.

The constant provides a clear fallback value and is used consistently throughout the code.


Line range hint 101-116: LGTM! Well-implemented language change handling.

The implementation properly handles both system and specific language selections, with appropriate culture settings and async plugin updates.


180-183: LGTM! Clean implementation of system language option.

The system language option is properly added to the top of the list with localized display text.


Line range hint 72-208: Verify system language switching behavior.

The implementation looks solid, but please ensure comprehensive testing of the following scenarios:

  1. Initial selection of system language
  2. Switching between system and specific languages
  3. Application restart with system language selected
  4. Handling of unsupported system languages

Run the following script to check for potential edge cases in language handling:

✅ Verification successful

Implementation verified - system language switching is robust and safe.

The code handles all critical scenarios:

  • Proper system language detection with multiple fallback mechanisms
  • Consistent culture propagation across the application
  • Safe handling of unsupported system languages
  • Correct plugin notification of language changes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential issues in language handling

# Check for direct references to language codes that might bypass the system language logic
rg -g '!*.{Designer.cs,resx,xaml}' -l '"en"|"zh"|"de"' --type cs

# Check for consistency in language-related constant usage
rg -g '!*.{Designer.cs,resx,xaml}' "SystemLanguageCode|DefaultLanguageCode" --type cs

# Look for potential culture-related issues
ast-grep --pattern 'CultureInfo.CurrentCulture' --lang cs

Length of output: 3435

This comment has been minimized.

This comment has been minimized.

@Jack251970 Jack251970 requested a review from jjw24 January 18, 2025 10:42
Copy link
Contributor

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 46c2c1f and abe943b.

📒 Files selected for processing (1)
  • Flow.Launcher.Core/Resource/Internationalization.cs (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (4)
Flow.Launcher.Core/Resource/Internationalization.cs (4)

21-21: LGTM! Good constant extraction.

The addition of DefaultLanguageCode reduces magic string duplication and SystemLanguageCode field properly encapsulates the system language state.

Also applies to: 26-26


31-31: LGTM! Proper initialization of readonly field.

The SystemLanguageCode is correctly initialized in the constructor.


206-208: LGTM! Clean implementation of system language option.

The system language option is properly added as the first item with appropriate translation.


98-109: LGTM! Well-structured language change handling.

The implementation correctly:

  1. Handles system language detection
  2. Preserves the "system" setting while using actual language for UI
  3. Updates both culture and UI culture appropriately

Let's verify the language change behavior:

Also applies to: 127-142

✅ Verification successful

Verified: Language change implementation is properly centralized and consumed

The codebase correctly:

  • Centralizes all culture changes in Internationalization.cs
  • Uses CurrentCulture appropriately for formatting in other locations
  • Maintains proper system language support without conflicts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify language change implementation
# Look for other places in the codebase that might need similar system language handling

# Check for direct CurrentCulture usage that might need updating
rg "CultureInfo\.CurrentCulture" -l

# Check for other language-related settings that might need system language support
rg "Language\s*=\s*[\"']system[\"']" -l

Length of output: 415


Script:

#!/bin/bash
# Check how CurrentCulture is used in the identified files
rg "CultureInfo\.CurrentCulture" -B 2 -A 2

# Also check for any Thread.CurrentThread.CurrentCulture usage
rg "Thread.*CurrentCulture" -B 2 -A 2

# Look for any other culture-related settings
rg "Culture(Info)?\." -B 2 -A 2

Length of output: 15927

Flow.Launcher.Core/Resource/Internationalization.cs Outdated Show resolved Hide resolved

This comment has been minimized.

@jjw24
Copy link
Member

jjw24 commented Jan 25, 2025

I just renamed the GetSystemLanguageCode to be more descriptive about its intended usage.

Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
ℹ️ candidate-pattern 1
❌ forbidden-pattern 22
⚠️ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

Pattern suggestions ✂️ (1)

You could add these patterns to .github/actions/spelling/patterns.txt:

# Automatically suggested patterns

# hit-count: 1 file-count: 1
# Non-English
[a-zA-Z]*[ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź][a-zA-Z]{3}[a-zA-ZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿĀāŁłŃńŅņŒœŚśŠšŜŝŸŽžź]*

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@jjw24 jjw24 added enhancement New feature or request and removed 5 min review labels Jan 25, 2025
@jjw24 jjw24 added this to the 1.20.0 milestone Jan 25, 2025
Copy link
Contributor

@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

🧹 Nitpick comments (1)
Flow.Launcher.Core/Resource/Internationalization.cs (1)

40-66: LGTM! Consider adding debug logging.

The implementation correctly handles system language detection at startup with proper fallback. Consider adding debug logging when falling back to the default language to help troubleshoot language detection issues.

 if (string.Equals(languageCode, twoLetterCode, StringComparison.OrdinalIgnoreCase) ||
     string.Equals(languageCode, threeLetterCode, StringComparison.OrdinalIgnoreCase) ||
     string.Equals(languageCode, fullName, StringComparison.OrdinalIgnoreCase))
 {
     return languageCode;
 }
}

+Log.Debug($"|Internationalization.GetSystemLanguageCodeAtStartup|No matching language found for system culture {fullName}, falling back to {DefaultLanguageCode}");
return DefaultLanguageCode;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66b3f5a and 0e700cd.

📒 Files selected for processing (1)
  • Flow.Launcher.Core/Resource/Internationalization.cs (5 hunks)
🔇 Additional comments (5)
Flow.Launcher.Core/Resource/Internationalization.cs (5)

21-21: LGTM! Good constant extraction.

Moving the default language code to a constant and making SystemLanguageCode readonly improves code maintainability.

Also applies to: 26-26


31-31: LGTM! Correctly initializes system language at startup.

This initialization addresses the previous issue where CultureInfo.CurrentCulture could be affected by language changes.


99-111: LGTM! Clean system language handling.

The changes correctly handle system language detection and delegation to the new overload.


208-210: LGTM! Clean system language option implementation.

The system language option is correctly added at the start of the list with proper translation.


Line range hint 129-144: Consider potential race condition in async plugin update.

The async plugin metadata update could potentially race with subsequent language changes. Consider using a cancellation token or synchronization mechanism.

Copy link
Member

@jjw24 jjw24 left a comment

Choose a reason for hiding this comment

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

👍

@jjw24 jjw24 enabled auto-merge January 25, 2025 23:46
@jjw24 jjw24 merged commit 32bedde into Flow-Launcher:dev Jan 25, 2025
4 checks passed
@Jack251970 Jack251970 deleted the dev2 branch January 26, 2025 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants