i18n-ally icon indicating copy to clipboard operation
i18n-ally copied to clipboard

add `typesafe-18n` support

Open ivanhofer opened this issue 3 years ago • 13 comments

What framework do you want to have? Please provide links of its i18n solution/package. https://github.com/ivanhofer/typesafe-i18n

Please provide some overall screenshots about how the i18n usage would be like

  • svelte image
  • react image
  • angular image image

Please provide a minimal starter project https://github.com/ivanhofer/typesafe-i18n

There are angular, svelte and react examples inside the examples folder

Additional context

I tried to get it working using this wiki-page, The keys show up, but the locale files are not detected. I could not figure out how. Please help!

# .vscode/i18n-ally-custom-framework.yml

languageIds:
   - javascript
   - typescript
   - javascriptreact
   - typescriptreact
   - html
   - svelte

usageMatchRegex:
   - "LL\\.([^(]+)\\("

# refactorTemplates:
#  - LL.$1()

monopoly: true

ivanhofer avatar Oct 16 '21 05:10 ivanhofer

Great localization package! Usually, the extension works with keys as strings, so some tweaks may be needed.

terales avatar Oct 18 '21 13:10 terales

Hi @terales, thanks! What exactly do you mean with "keys as strings"? The keys are already detected, but the issue is that the language files are not detected.

ivanhofer avatar Oct 18 '21 14:10 ivanhofer

Currently I have this vaguely working with the following configs.

.vscode/settings.json

{
	"i18n-ally.localesPaths": ["src/lib/i18n"],
	"i18n-ally.pathMatcher": "{locale}/index.{ext}",
	"i18n-ally.enabledParsers": ["ts", "js"]
}

.vscode/i18n-ally-custom-framework.yml

languageIds:
  - javascript
  - typescript
  - svelte

usageMatchRegex:
  - "\\$?LL\\.({key})\\(\\)"

# refactorTemplates:
#   - '{$LL.$1()}'
#   - '{LL.$1()}'
#   - '$LL.$1()'
#   - 'LL.$1()'

monopoly: true

Here's a screenshot of the result.

Screenshot

Juici avatar Oct 18 '21 14:10 Juici

@Juici wow, looks really cool 👍 I will try it on some of my projects the next days

ivanhofer avatar Oct 18 '21 15:10 ivanhofer

@Juici I have tweaked the config a bit and this is now the config I use:

.vscode/settings.json

{
   "i18n-ally.pathMatcher": "{locale}/index.{ext}",
   "i18n-ally.enabledParsers": ["ts", "js"],
   "i18n-ally.keystyle": "nested",
   "i18n-ally.localesPaths": ["src/i18n"]
}

.vscode/i18n-ally-custom-framework.yml

languageIds:
   - typescript
   - javascript
   - typescriptreact
   - javascriptreact
   - svelte
   - html

usageMatchRegex:
   - "\\$?LL\\.({key})\\(((\\{.*\\})|([^)]*))\\)"

refactorTemplates:
   - '{$LL.$1()}'
   - '{LL.$1()}'
   - '$LL.$1()'
   - 'LL.$1()'

monopoly: true

It works really great! I will try to convert that config to a Framework class

ivanhofer avatar Oct 20 '21 05:10 ivanhofer

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 19 '21 05:12 stale[bot]

There is an open PR for this issue: #681

ivanhofer avatar Dec 19 '21 14:12 ivanhofer

@ivanhofer usageMatchRegex also matches cases like LL.foo[dymanic_value]() which i18n-ally has no way of inferring and throws en: i18n key "foo[dynamic_value]" does not exist. So yes, it might need some more tweaks as @terales suggested.

Flammae avatar Dec 29 '22 17:12 Flammae

@beqaMeqvabishvili thanks for your feedback. What should I do if i18n-ally does not support it?

ivanhofer avatar Dec 30 '22 07:12 ivanhofer

@ivanhofer Not sure. To be honest I don't even know how to even go around building a tool of this scale. I guess it would require some refactoring on i18n-ally's side to get it working

Flammae avatar Dec 30 '22 13:12 Flammae

Probably yes. But the project seems to have been abandoned. It doesn't look like there will be released new versions of this project.

ivanhofer avatar Dec 30 '22 13:12 ivanhofer

If you're getting this error while integrating i18n-ally and typesafe-i18n on vscode: TSError: ⨯ Unable to compile TypeScript: error TS5095: Option 'preserveValueImports' can only be used when 'module' is set to 'es2015' or later.

I found a workaround to fix it: cd ~/.vscode/extensions/lokalise.i18n-ally-2.8.1/ yarn add -D ts-node touch src/i18n/package.json

here's my package.json: { "name": "phantom-i18n" }

You should also think about adding /src/i18n/package.json in your .gitignore (if you're working with a team)

mvartuc avatar Apr 04 '23 15:04 mvartuc

If someone goes from Google, I add a little hack that allow write your localization in .ts files (because original extension is doesn't support that). It's some weird but worked for my case

https://github.com/lokalise/i18n-ally/pull/1071

whalemare avatar Jan 08 '24 19:01 whalemare