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 typesafe-18n support #678

Open
ivanhofer opened this issue Oct 16, 2021 · 13 comments
Open

add typesafe-18n support #678

ivanhofer opened this issue Oct 16, 2021 · 13 comments

Comments

@ivanhofer
Copy link

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
@terales
Copy link
Collaborator

terales commented Oct 18, 2021

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

@ivanhofer
Copy link
Author

ivanhofer commented Oct 18, 2021

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.

@Juici
Copy link

Juici commented Oct 18, 2021

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

@ivanhofer
Copy link
Author

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

@ivanhofer
Copy link
Author

ivanhofer commented Oct 20, 2021

@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

@stale
Copy link

stale bot commented Dec 19, 2021

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 stale bot added the stale label Dec 19, 2021
@ivanhofer
Copy link
Author

There is an open PR for this issue: #681

@stale stale bot removed the stale label Dec 19, 2021
@Flammae
Copy link

Flammae commented Dec 29, 2022

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

@ivanhofer
Copy link
Author

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

@Flammae
Copy link

Flammae commented Dec 30, 2022

@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

@ivanhofer
Copy link
Author

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

@mvartuc
Copy link

mvartuc commented Apr 4, 2023

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)

@whalemare
Copy link

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

#1071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants