ivanhofer / typesafe-i18n

A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.

Home Page:https://github.com/ivanhofer/typesafe-i18n

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

remove argument-types inside translations for production bundle

ivanhofer opened this issue · comments

If you use types inside your base-translations, the type-information is also part of the generated output. Since this information is only needed for the watcher to output better types, it can be omitted in production builds to save a few bytes from the bundle.

We could automatically remove all argument types for production

if you have a translation like this:

export const en = {
   HI: 'Hello {name:string}!'
   // other translations
}

it could be optimize to the following code:

export const en = {
   HI: 'Hello {name}!'
   // other translations
}

What needs to be done:

  • simple implementation, assuming all translation-strings live inside the index.ts file
  • advanced implementation, where all strings e.g. from imports inside the index.ts are considered
  • (optional) create an updated string-parser that doesn't try to parse the type from the translations to improve output size by a few bytes