Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/src/store/modules/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const GlobalStore = defineStore({
this.csrfToken = token;
},
updateLanguage(language: any) {
if (language === 'pt-BR') {
language = 'pt-br';
}
this.language = language;
localStorage.setItem('lang', language);
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The provided code looks mostly okay, but there are a few improvements you could consider:

  1. Remove redundant assignment: In the updateLanguage function, if the received language is 'pt-BR', it gets re-assigned to lowercase 'pt-br'. This can be simplified by directly using lowercase in the condition.

  2. Consider locale formatting: If the application deals with text based on locale-specific formats (like dates or numbers), you might want to ensure consistency and handle cases where locales don't have specific configurations for certain languages.

  3. Update comments: It's beneficial to add comments explaining why the code changes were made.

Here's an optimized version of the code with these considerations implemented:

const GlobalStore = defineStore({
    state: () => ({
        csrfToken: null,
        language: null,
    }),
    actions: {
        setCsrfToken(token: string) {
            this.csrfToken = token;
        },
        updateLanguage(language: any) {
            // Ensure the language is consistently uppercase 'pt-BR'
            const normalizedLang = language.toUpperCase() === 'PT-BR' ? 'pt-br' : language;

            this.language = normalizedLang;
            localStorage.setItem('lang', normalizedLang);

            // Additional logic for handling different regions if necessary
            switch (normalizedLang.toLowerCase()) {
                case 'es-la':
                    console.log('Switched to Spanish (Latin America)');
                    break;
                case 'fr-fr':
                    console.log('Switched to French');
                default:
                    console.log(`Defaulting to user-defined language`);
            }
        },
    },
});

These additions will help maintain proper casing rules and potentially improve performance slightly due to fewer checks. Additionally, adding comments provides clear understanding of how each part of the code works.

Expand Down
Loading