Skip to content

Conversation

@derkoe
Copy link
Contributor

@derkoe derkoe commented Jan 18, 2022

With this change you can use JSON as the source for your translation texts. See #151

Then plain JSON can be used to store the texts (with en as the base language):

src/i18n/en/index.ts:

import * as en from './texts.json';
export default en;

src/i18n/en/texts.json:

{
    "HI": "Hello {name}!",
    "BYE": "Bye bye"
}

src/i18n/de/index.ts:

import type { Translation } from '../i18n-types'
import * as deJson from './texts.json'
const de: Translation = deJson;
export default de

src/i18n/en/texts.json:

{
    "HI": "Hallo {name}!",
    "BYE": "Auf Wiedersehen"
}

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time.
  • Prefix your PR title with [feat], [fix], [chore], or [docs].
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm run test and lint the project with pnpm run lint

@ivanhofer
Copy link
Collaborator

ivanhofer commented Jan 18, 2022

Thanks for this PR.
Could you please also update CHANGELOG.md?
It will be a minorversion bumb 😉

@ivanhofer ivanhofer merged commit 88cab6d into codingcommons:main Jan 18, 2022
@bitdom8
Copy link

bitdom8 commented May 28, 2022

Thanks @derkoe

@whalemare
Copy link
Contributor

whalemare commented Jan 11, 2023

This is worked only as json importing and not for a translations type checking, right?
Types inside not base json files always be "string", because of typescript limitations

Снимок экрана 2023-01-11 в 12 01 52

@ivanhofer
Copy link
Collaborator

yes, this is a limitation on how TypeScripts type system parses the json file

@bitdom8
Copy link

bitdom8 commented Jan 11, 2023

Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants