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 vue-i18n (#116) #673

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eidottermihi
Copy link
Member

@eidottermihi eidottermihi commented Dec 30, 2024

Description

Adds vue-i18n plugin to allow centralized text definition and enable i18n if needed.

I only added a german translation (src/locales/de.yaml) as the static texts were already german. So it's up to the application developers to add additional translation files (when they are needed).

Some conventions are enforced by eslint-plugin-vue-i18n:

  • camelCase for message keys
  • no unused message keys
  • no duplicate keys

If application developers don't want to use vue-i18n for centralizing text definitions (like mentioned by @darenegade in #116 ) they are still not forced to do so. By setting the eslint rule @intlify/vue-i18n/no-raw-text to off they also can remove lint warnings if they choose to include raw text in components or views.

Reference

Issues #116

Summary by CodeRabbit

  • New Features

    • Added comprehensive internationalization (i18n) support for the application.
    • Implemented German language localization.
    • Introduced dynamic translations across multiple components and views.
  • Chores

    • Updated ESLint configuration to enforce i18n best practices.
    • Added new dependencies for internationalization.
    • Configured TypeScript and Vite to support localization.
  • Documentation

    • Created German localization file with translations for app elements, views, and common actions.
    • Added README for managing translation files and guidelines.

@eidottermihi eidottermihi requested a review from a team as a code owner December 30, 2024 10:46
Copy link

coderabbitai bot commented Dec 30, 2024

Walkthrough

The pull request introduces comprehensive internationalization (i18n) support to the frontend application. The changes span multiple files, adding Vue I18n plugin configurations, localization files, and updating components to use dynamic translations. The implementation focuses on German localization, systematically replacing hardcoded text with translatable keys. Modifications include updates to the ESLint configuration, package dependencies, and TypeScript type definitions to fully integrate internationalization capabilities.

Changes

File Change Summary
eslint.config.js Added Vue I18n ESLint plugin with rules for internationalization best practices
package.json Added i18n-related dependencies: @intlify/unplugin-vue-i18n, vue-i18n, @intlify/eslint-plugin-vue-i18n
src/App.vue, src/views/HomeView.vue, src/views/GetStartedView.vue Replaced hardcoded text with t() translation function calls
src/components/TheSnackbar.vue, src/components/common/YesNoDialog.vue Added i18n support for button and dialog text
src/locales/de.yaml Created German localization file with comprehensive translation keys
src/plugins/i18n.ts Implemented i18n plugin configuration with datetime formatting
src/plugins/index.ts Registered i18n plugin in the Vue application
vite.config.ts Configured Vite to include Vue I18n plugin
tsconfig.app.json Updated TypeScript types for i18n support
src/locales/README.md Added guidelines for managing translation files

Sequence Diagram

sequenceDiagram
    participant App as Vue Application
    participant I18n as Vue I18n Plugin
    participant Locale as Locale Files
    
    App->>I18n: Initialize with locale
    I18n->>Locale: Load translation files
    App->>I18n: Request translation for key
    I18n-->>App: Return translated text
Loading

Poem

🐰 A Rabbit's Ode to Localization 🌍

In lines of code, translations bloom,
No more static text to consume
German words now dance with grace
Internationalized, we embrace!
Vue I18n, our linguistic friend
Making languages beautifully blend! 🌈

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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

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.

@github-actions github-actions bot added the Template: Frontend Issues regarding the frontend template. label Dec 30, 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: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 21e58b8 and d7bd27d.

⛔ Files ignored due to path filters (1)
  • refarch-frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • refarch-frontend/eslint.config.js (3 hunks)
  • refarch-frontend/package.json (1 hunks)
  • refarch-frontend/src/App.vue (4 hunks)
  • refarch-frontend/src/components/TheSnackbar.vue (1 hunks)
  • refarch-frontend/src/components/common/YesNoDialog.vue (2 hunks)
  • refarch-frontend/src/locales/de.yaml (1 hunks)
  • refarch-frontend/src/plugins/i18n.ts (1 hunks)
  • refarch-frontend/src/plugins/index.ts (1 hunks)
  • refarch-frontend/src/views/GetStartedView.vue (6 hunks)
  • refarch-frontend/src/views/HomeView.vue (2 hunks)
  • refarch-frontend/tests/unit/example.spec.ts (2 hunks)
  • refarch-frontend/tsconfig.app.json (1 hunks)
  • refarch-frontend/vite.config.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
refarch-frontend/vite.config.ts

[error] 3-3: A Node.js builtin module should be imported with the node: protocol.

Using the node: protocol is more explicit and signals that the imported module belongs to Node.js.
Unsafe fix: Add the node: protocol.

(lint/style/useNodejsImportProtocol)

🔇 Additional comments (34)
refarch-frontend/src/components/TheSnackbar.vue (3)

15-15: Localization key usage looks good!

Using t("common.actions.close") here aligns perfectly with your i18n structure. Ensure you monitor changes to common.actions.close in the locale files to keep the UI consistent.


22-22: Importing useI18n is aligned with the new i18n implementation.

This import is necessary and sufficiently scoped to handle all translations in this component.


28-29: Integration of the i18n instance is well done.

Destructuring t from useI18n() is a concise approach that keeps the component code clean and consistent. Consider verifying locale availability when adding more translations.

refarch-frontend/src/views/GetStartedView.vue (4)

5-8: All good on the heading and subheading changes.

Thank you for replacing hardcoded strings with dynamic translations using t("views.getStarted.dokuHeader") and t("views.getStarted.dokuSubtext"). This helps maintain uniform i18n support across the application.


58-59: Good approach to translating dialog titles and text.

Leveraging the t('views.getStarted.saveLeave.title') and t('views.getStarted.saveLeave.text') ensures the dialog contents will be easily adjustable for different languages.


68-74: i18n setup is correct.

The import useI18n and the destructuring of t are straightforward and well-aligned with Vue I18n usage patterns. This is fundamental to enabling translations.


Line range hint 15-51: Consistent usage of translation keys for links.

Each link text is now localized with t("views.getStarted.dokuLinks.XXX"). This maintains consistency and ensures that translators need only update language files, not references in multiple files. Nicely done!

You might want to ensure that all keys reference the correct German translations in your de.yaml or any fallback locale by running a quick search for these keys in the translation files.

✅ Verification successful

Let me search for these translation keys in the locale files to verify their existence.


Let me try a different approach to locate the translation files.


I found the German translation file. Let's check its content to verify the translation keys.


All translation keys are properly defined in the German locale file

I've verified that all the translation keys used in the links are correctly defined in the German translation file (de.yaml) under the path views.getStarted.dokuLinks:

  • barrakuda: "Barrakuda-Doku"
  • apiGateway: "Doku Archetype API-Gateway"
  • backend: "Doku Archetype Backend"
  • archetypesRepo: "Git-Repo Archetypes"
  • javascriptWiki: "Javascript-Wiki"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for translation keys used here to ensure they exist in the locale files
rg "views\.getStarted\.dokuLinks\."

Length of output: 596


Script:

#!/bin/bash
# Search for translation files
fd -e yaml -e json "translations|locales|i18n"

# Let's also check the content of any found translation files
fd -e yaml -e json "translations|locales|i18n" --exec cat {}

Length of output: 113


Script:

#!/bin/bash
# Try to find any yaml or json files that might contain translations
fd -e yaml -e json . 

# Also search for any imports of translation files
rg -i "import.*\.(yaml|json)" -A 2

Length of output: 1363


Script:

#!/bin/bash
# Check content of the German translation file
cat refarch-frontend/src/locales/de.yaml

Length of output: 1346

refarch-frontend/src/plugins/index.ts (2)

3-3: Use of i18n import is consistent with project architecture.
This import cleanly integrates internationalization support.


9-9: Chain registration of i18n plugin.
Great job adding .use(i18n) to the existing plugin registration chain for a seamless i18n setup.

refarch-frontend/tests/unit/example.spec.ts (2)

9-9: Importing i18n for test environment.
Including i18n in unit tests ensures accurate coverage of localized text and avoids missing translation errors.


32-32: Mounting TheSnackbar with i18n plugin.
Providing the i18n plugin in the test environment is essential for verifying translated strings in the component.

refarch-frontend/src/plugins/i18n.ts (2)

10-36: Well-defined date/time formats for German locale.
The structured datetimeFormats nicely covers short, long, and timestamp variations. This ensures consistency of date/time presentation.


38-44: Creating and exporting the i18n instance.
Setting both locale and fallbackLocale to "de" is suitable for a German-only app. In the future, you can extend this to support additional locales as needed.

refarch-frontend/src/views/HomeView.vue (4)

14-14: Replacing static header text with translation key.
This dynamically translates the header, enhancing the bilingual or multilingual readiness of the application.


17-17: Localized text for API gateway status.
Using t("views.home.apiGatewayStatus") ensures consistent translations across different locales if added later.


27-27: Importing useI18n for localized UI content.
Explicitly importing and declaring useI18n ensures the component can call t() for dynamic translations.


34-35: Destructuring the translation function.
Using const { t } = useI18n(); is a neat approach for concise references to t in the template and script.

refarch-frontend/vite.config.ts (2)

5-5: vue-i18n plugin addition looks good.

Integrating the @intlify/unplugin-vue-i18n/vite plugin is consistent with the project's i18n strategy and appears correctly imported.


36-38: Expand testing of locale files.

The plugin’s include pattern restricts transformations to ./src/locales/**. Ensure that newly added or future locale files are placed in the same location so they are included properly. If there is a possibility of storing locale files in other directories, consider adjusting the pattern accordingly.

refarch-frontend/eslint.config.js (4)

2-2: vueI18n plugin import confirmed.

The import is aligned with the plugin usage below, ensuring the lint rules are properly integrated.


15-15: Included recommended i18n config is appropriate.

Bringing in the plugin’s recommended flat configuration enforces good i18n practices by default.


28-40: i18n-specific rules appear well configured.

You’re enforcing naming conventions (camelCase) and preventing unused or duplicate keys. Keeping no-raw-text at “warn” is a balanced approach, allowing devs to override it if desired. Overall, this fosters consistent i18n usage.


41-45: Localization settings are comprehensive.

Defining localeDir and messageSyntaxVersion ensures consistent checking and syntax requirements for your YAML-based translations. This is a solid practice to keep your i18n structure maintainable.

refarch-frontend/src/App.vue (3)

13-15: Localized app name updates.

Replacing hardcoded text with translated keys is a key i18n best practice. The dynamic usage of t("app.name.partX") streamlines future language expansion.


61-63: Navigation link translation.

Good job externalizing strings for the “Get started” navigation text. This ensures it can be easily translated or modified later without touching component logic.


84-84: useI18n import & usage well-structured.

Destructuring t for template interpolation is a standard, clean approach. Continuing this pattern across components will maintain consistency.

Also applies to: 111-111

refarch-frontend/tsconfig.app.json (1)

13-13: Extended type definitions for i18n.

Including "@intlify/unplugin-vue-i18n/messages" in compilerOptions.types ensures improved type checking and eliminates potential type errors when accessing messages via vue-i18n.

refarch-frontend/package.json (1)

18-18: Verify vue-i18n related package versions

Let's verify if these are the latest stable versions and check for any security advisories.

Also applies to: 23-23, 28-28

✅ Verification successful

✅ All vue-i18n related packages are using latest versions with no known vulnerabilities

The verification shows that all packages are using their latest stable versions:

  • @intlify/unplugin-vue-i18n@6.0.3 (latest: 6.0.3)
  • vue-i18n@11.0.1 (latest: 11.0.1)
  • @intlify/eslint-plugin-vue-i18n@3.2.0 (latest: 3.2.0)

While there are known vulnerabilities in older versions of vue-i18n (9.x and 10.x), the version being used (11.0.1) is not affected. No vulnerabilities were found for the other two packages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check latest versions and security advisories for vue-i18n packages
echo "Checking latest versions from npm registry..."
for pkg in "@intlify/unplugin-vue-i18n" "vue-i18n" "@intlify/eslint-plugin-vue-i18n"; do
  echo "Package: $pkg"
  curl -s "https://registry.npmjs.org/$pkg" | jq -r '.["dist-tags"].latest'
done

# Check for known vulnerabilities
echo "Checking for vulnerabilities..."
for pkg in "@intlify/unplugin-vue-i18n" "vue-i18n" "@intlify/eslint-plugin-vue-i18n"; do
  gh api graphql -f query="
    query {
      securityVulnerabilities(first: 5, ecosystem: NPM, package: \"$pkg\") {
        nodes {
          advisory {
            summary
            severity
            publishedAt
          }
          vulnerableVersionRange
        }
      }
    }"
done

Length of output: 3043

refarch-frontend/src/locales/de.yaml (2)

28-44: LGTM! Comprehensive view translations with proper escaping.

The view translations are well-structured and properly handle special characters (e.g., it{'@'}M). The navigation and documentation sections are complete.


14-20: Verify the linked message concatenation

The app name concatenation using @: syntax looks correct, but please verify the rendering in the UI to ensure no unwanted spaces are introduced.

✅ Verification successful

No unwanted spaces in app name concatenation

Based on the App.vue implementation, the app name is not using the concatenated app.name.full key, but rather renders each part separately with proper styling:

<span class="text-white">{{ t("app.name.part1") }}</span>
<span class="text-secondary">{{ t("app.name.part2") }}</span>
<span class="text-white">{{ t("app.name.part3") }}</span>

This approach actually provides better control over styling and spacing than using the concatenated version, ensuring no unwanted spaces are introduced. The concatenated key app.name.full appears to be unused in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of the concatenated app name
echo "Checking usage of app.name.full..."
rg -l "t\(['\"]app\.name\.full['\"]" src/

Length of output: 171


Script:

#!/bin/bash
# Search for usage of the concatenated app name with corrected path
echo "Checking usage of app.name.full..."
rg -l "t\(['\"]app\.name\.full['\"]" refarch-frontend/src/

# Also search for other potential translation usages
echo -e "\nChecking other translation patterns..."
rg -l "useTranslation|t\(['\"]app\.name" refarch-frontend/src/

# Check content of any component files that might use the app name
echo -e "\nChecking content of potential component files..."
fd -e tsx -e jsx -e ts -e js . refarch-frontend/src/ --exec cat {}

Length of output: 15801


Script:

#!/bin/bash
# Let's check the App.vue file specifically since it was found in the translation pattern search
echo "Checking App.vue content..."
cat refarch-frontend/src/App.vue

# Also check for any vue files that might use the app name
echo -e "\nChecking vue files for app name usage..."
rg -l "app\.name" refarch-frontend/src/ --type vue

Length of output: 4367

refarch-frontend/src/components/common/YesNoDialog.vue (4)

41-41: Good use of translation keys for 'No'.
This change replaces hard-coded text with an i18n translation key, aligning with the project’s internationalization efforts. Ensure that "common.no" is defined in your translation files (e.g., de.yaml).


48-48: Good use of translation keys for 'Yes'.
As with "common.no", confirm that "common.yes" is appropriately translated in all supported locales.


56-56: Import statement for useI18n looks good.
This is required to access t for translations. Make sure this import is consistently used throughout the codebase wherever translations are needed.


68-69: Well-structured usage of the i18n composition API.
Destructuring t from useI18n() is a clean approach, keeping translation calls concise. Continue to maintain the convention of referencing t("namespace.key") for clarity.

refarch-frontend/vite.config.ts Outdated Show resolved Hide resolved
refarch-frontend/package.json Show resolved Hide resolved
refarch-frontend/src/locales/de.yaml Show resolved Hide resolved
refarch-frontend/src/locales/de.yaml 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: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7bd27d and c2012d7.

📒 Files selected for processing (2)
  • refarch-frontend/src/locales/README.md (1 hunks)
  • refarch-frontend/vite.config.ts (2 hunks)
🧰 Additional context used
🪛 Markdownlint (0.37.0)
refarch-frontend/src/locales/README.md

16-16: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


30-30: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


33-33: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


60-60: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (4)
refarch-frontend/vite.config.ts (3)

2-2: LGTM! Using recommended node: protocol.

The import statement correctly uses the node: protocol for Node.js builtin modules.


5-5: LGTM! Vue I18n plugin import.

The plugin import is correctly placed with other Vite plugins.


36-38: LGTM! Verify locale files path.

The Vue I18n plugin configuration looks good. The path resolution is correct and the glob pattern will support multiple locale files.

Let's verify the locale files setup:

✅ Verification successful

Locale files setup is correctly configured and functional

The verification confirms that:

  • The locales directory exists at the correct path: refarch-frontend/src/locales/
  • The German translation file de.yaml is present and contains valid YAML structure
  • The path resolution in the Vue I18n plugin configuration correctly matches the actual file structure

The locale setup follows i18n best practices with:

  • Well-organized translation keys in hierarchical structure
  • Support for nested keys and interpolation
  • Documentation (README.md) present in the locales directory
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the locale files structure and content

# Check if the locales directory exists and contains yaml files
fd -e yaml . src/locales

# Verify the German translation file exists and is valid YAML
if [ -f "src/locales/de.yaml" ]; then
  echo "German translation file exists"
  # Basic YAML validation (will error if invalid)
  cat src/locales/de.yaml | yq eval '.' - >/dev/null
fi

Length of output: 158


Script:

#!/bin/bash
# Let's check if the locales directory exists anywhere in the repository
fd locales

# Also search for any YAML files that might contain translations
fd -e yaml -e yml

# Let's also check the content of the vite.config.ts to see the full context
cat refarch-frontend/vite.config.ts

Length of output: 1960


Script:

#!/bin/bash
# Let's check the content of the German translation file
cat refarch-frontend/src/locales/de.yaml

# List all files in the locales directory to ensure we're not missing any
ls -la refarch-frontend/src/locales/

Length of output: 1616

refarch-frontend/src/locales/README.md (1)

1-73: Documentation provides comprehensive guidance for i18n implementation.

The README effectively communicates the translation management strategy, aligning perfectly with the PR objectives of integrating vue-i18n. The hierarchical organization, naming conventions, and best practices will help maintain consistency across the project.

🧰 Tools
🪛 Markdownlint (0.37.0)

16-16: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


30-30: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


33-33: null
Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


60-60: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

refarch-frontend/src/locales/README.md Show resolved Hide resolved
refarch-frontend/src/locales/README.md Show resolved Hide resolved
refarch-frontend/src/locales/README.md Show resolved Hide resolved
refarch-frontend/src/locales/README.md Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Template: Frontend Issues regarding the frontend template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant