You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Investigate ways of generating _locales based on translation files #217
No, I meant... For someone who's not using vue-i18n and only relies on browser.i18n he'd be defining a mess in public/_locales because the syntax is too verbose.
But if someone wanted to use vue-i18n they'd be defining only extension name and description within the context of browser.i18n and the rest can all live inside vue-i18n locale dir.
Am I right? If not, I'd be trying to figure out the way to use only vue-i18n and somehow at the build-time generate locales needed for parts that browser.i18n can access, such as manifest.json file property values.
@dvlden Yes, that is an option, that could be a simple Vite plugin. I need to research other patterns before committing to adding that logic to WXT directly. I don't want to add something that only works for one framework's one library.
Goal here is to provide some kind of vite plugin or config option to generate the _locales directory from another localization file. This would also need to integrate with the type augmentation for browser.runtime.getMessage.
You shouldn't have to manage translation files in multiple directories.
changed the title [-]Investigate ways of generating `_locales` based on more standard translation files[/-][+]Investigate ways of generating `_locales` based on translation files[/+]on Nov 7, 2023
Interesting tool, I hadn't heard about it before. I don't think it is the solution to combining manifest translations and other translation files though...
Yes, supporting this tool will greatly simplify the checking and editing of i18n files (it likely already support Chrome i18n and vue-i18n).
Also, I have reviewed the i18n and vue-i18n wxt-examples and have gained a basic understanding of the situation. The current official structure, as per Google Chrome's standards, is:
For vue-i18n, WXT needs an official solution for the manifest, and a *.json solution for other files:
assets/locales/en.json
assets/locales/ko.json
The objective is to utilize assets/locales/*.json for all i18n tasks (including manifest) across all frameworks, aiming to make this a built-in feature for WXT, possibly supporting the Google Chrome official solution simultaneously.
Additionally, WXT requires a feature similar to useI18n to ensure type safety by verifying message keys exist.
For the most part. Type-safety is a nice-to-have, not 100% necessary.
It also needs to support react, Svelte, and any other i18n libraries. This is why I mentioned a custom vite plugin rather than something built into WXT - supporting every i18n library in core would not be a good approach.
Creating separate plugins for each library could be a solution.
If type safety is not a concern, then actually, a plugin might not be necessary.
Because the process of converting from assets/locales/<lang>.json to public/_locales/<lang>/messages.json is independent of the framework.
You shouldn't have to manage translation files in multiple directories.
Initially, it was a bit confusing because I thought solving the problem mentioned above merely required a pure JavaScript implementation that should be independent of any framework, as it only needs to move the file from assets/locales/<lang>.json to public/_locales/<lang>/messages.json.
features like placeholders, re-using strings, currency, and pluralization are different between most libraries
This might not always hold true. For example, i18next is somewhat framework-independent:
Ok, I'm convinced that WXT can't provide a solution for all localization frameworks, but it should be able to improve the existing i18n APIs and localization files.
Here's what I propose:
Create a new folder called locales/ recognized by WXT
Place any files with translations directly in it (support YAML, JSON 5, and regular JSON)
Improve the format of the localization files themselves (nested keys, optionally use a simple string instead of an object with a message, etc)
I'll share a complete example of what I'm thinking in a bit.
For example, my GitHub Better Line Counts extension. It's not localized, but if I were to localize it, it would look something like this:
src/
locales/
en.yml
...
# src/locales/en.ymlname: GitHub Better Line Countsdescription: Remove generated files from GitHub line countsdiffs:
additionsText:
1: $count$ additionn: $count$ additionsdeletionsText:
1: $count$ deletionn: $count$ deletionsgeneratedText:
1: $count$ generated line.n: $count$ generated lines.additionsSymbol: +$count$deletionsSymbol: −$count$generatedSymbol: ⌁$count$options:
privateRepos:
title: Access Private Reposdescription1: "Optional:"description2: To recalculate the diff on private repos, the extension needs a GitHub PAT to authenticate API requests.description3: Click heredescription4: to create one.invalidToken: Token is invalidvalidToken: Token is validchecking: Checking token...username: "Username: {username}"enabled:
title: Show Generated Line Countsdescription1: Along withdescription2: +additionsdescription3: anddescription4: −deletionsdescription5: ", show a third number for"description6: ⌁generateddescription7: lines.customLists:
title: Custom Listsdescription1: Usedescription1: minimatchdescription1: glob patterns to mark files as generated accross all repos.allRepos: All ReposcustomRepoPlaceholder: | Enter glob patterns: *.lock **/vendor/**
Some comments:
You don't need to use the { message: ..., description?: ..., placeholders?: ... } form the Chrome extensions require. If you just set a string value for a key, WXT will convert to it the form chrome extensions expect. You can still use the longer form if you want.
Chrome doesn't have a built-in solution for pluralization. They recommend using "plural neutral forms" (Additions: $count$ instead of $count$ additions), which IMO doesn't always work. I plan on supporting plural forms, see diffs.*Text for an example.
Activity
[-]Investigate ways of generating `_locales` based on more standard translation files[/-][+]Investigate ways of generating `_locales` based on translation files[/+]mefengl commentedon Jan 3, 2024
I used an extension for VSCode called i18n-ally. I found it helpful, so I'm sharing it here in the hope that it might inspire solutions to this issue.
https://github.com/lokalise/i18n-ally
aklinker1 commentedon Jan 3, 2024
Interesting tool, I hadn't heard about it before. I don't think it is the solution to combining manifest translations and other translation files though...
https://github.com/lokalise/i18n-ally/wiki/Custom-Framework seems relevant, at least for adding editor support.
mefengl commentedon Jan 4, 2024
Yes, supporting this tool will greatly simplify the checking and editing of i18n files (it likely already support Chrome i18n and vue-i18n).
Also, I have reviewed the
i18nandvue-i18nwxt-examples and have gained a basic understanding of the situation. The current official structure, as per Google Chrome's standards, is:For vue-i18n, WXT needs an official solution for the manifest, and a *.json solution for other files:
The objective is to utilize
assets/locales/*.jsonfor all i18n tasks (including manifest) across all frameworks, aiming to make this a built-in feature for WXT, possibly supporting the Google Chrome official solution simultaneously.Additionally, WXT requires a feature similar to
useI18nto ensure type safety by verifying message keys exist.Is my understanding correct?
aklinker1 commentedon Jan 4, 2024
For the most part. Type-safety is a nice-to-have, not 100% necessary.
It also needs to support react, Svelte, and any other i18n libraries. This is why I mentioned a custom vite plugin rather than something built into WXT - supporting every i18n library in core would not be a good approach.
Creating separate plugins for each library could be a solution.
mefengl commentedon Jan 4, 2024
If type safety is not a concern, then actually, a plugin might not be necessary.
Because the process of converting from
assets/locales/<lang>.jsontopublic/_locales/<lang>/messages.jsonis independent of the framework.aklinker1 commentedon Jan 4, 2024
True, but features like placeholders, re-using strings, currency, and pluralization are different between most libraries.
So just reading JSON from one place won't always work.
mefengl commentedon Jan 5, 2024
Initially, it was a bit confusing because I thought solving the problem mentioned above merely required a pure JavaScript implementation that should be independent of any framework, as it only needs to move the file from
assets/locales/<lang>.jsontopublic/_locales/<lang>/messages.json.This might not always hold true. For example, i18next is somewhat framework-independent:
But I understand that you're referring to a more framework-native approach to usage:
nnx0r commentedon Jan 5, 2024
At the moment, I am opting out entirely of Vue i18n and using browser built-in i18n for all translation messages.
It is disaster to maintain, but I wouldn't want to use i18n dependency inside of injection script or background / worker.
aklinker1 commentedon Jan 6, 2024
Ok, I'm convinced that WXT can't provide a solution for all localization frameworks, but it should be able to improve the existing i18n APIs and localization files.
Here's what I propose:
locales/recognized by WXTI'll share a complete example of what I'm thinking in a bit.
aklinker1 commentedon Jan 6, 2024
For example, my GitHub Better Line Counts extension. It's not localized, but if I were to localize it, it would look something like this:
Some comments:
{ message: ..., description?: ..., placeholders?: ... }form the Chrome extensions require. If you just set a string value for a key, WXT will convert to it the form chrome extensions expect. You can still use the longer form if you want.Additions: $count$instead of$count$ additions), which IMO doesn't always work. I plan on supporting plural forms, seediffs.*Textfor an example.aklinker1 commentedon Jan 6, 2024
Closing this issue, will continue conversation on #327 if you have comments or suggestions about the API I've decided on.