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

Allow write to typescript files (typesafe-i18n support) #1071

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

Conversation

whalemare
Copy link

@whalemare whalemare commented Jan 8, 2024

This feature allows you to write your localizations directly to .ts files

It is written in a ugly way, so I have no illusions about its merge.
This PR exists simply to show that it is possible.

I needed to add support for the typesafe-i18n library, which uses typescript files by default. If you need the same thing, here’s how you can connect this fork:

Step 1

Build and install extension

git clone https://github.com/whalemare/i18n-ally
cd i18n-ally
git checkout feature/typesafe-i18n

yarn
yarn build
yarn vsce package

yarn vsce package - this command will build you an extension locally, which you can connect to the project according to this guide

Step 2

Create file .vscode/i18n-ally-custom-framework.yml and put content similar to this:

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

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

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

# template for each language that will be used when write in file.
# $1 will be replaced with JSON.stringify(data, null, 2), so you should write linter after it
tsFileTemplates:
  - 'en/index.ts': "import type { BaseTranslation } from '../i18n-types'\n\nconst en = $1 satisfies BaseTranslation\n\nexport default en\n"
  # when template not found will be used 'default'
  - 'default': "import type { Translation } from '../i18n-types'\n\nexport default $1 satisfies Translation\n"
  
  monopoly: true

@dBianchii
Copy link

  • 1!

@cod3rboy
Copy link

cod3rboy commented Aug 9, 2024

Any update on this?

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

Successfully merging this pull request may close these issues.

3 participants