Skip to content

How would one use I18n in TS classes? #566

Answered by albe2669
albe2669 asked this question in Q&A
Discussion options

You must be logged in to vote

Hmm... When is the variable instantiated?
Because something funky is going on here.

I have a class, let's call it class1. Then i have a class called I18nModule, which looks like this:

export type I18nType = I18n<LocaleMessages<VueMessageType>, unknown, unknown, false>;

export default class I18nModule {
  readonly name = '18n';

  i18n!: I18nType;

  constructor() {
    this.install();
  }

  install(): void {
    this.i18n = createI18n({
      legacy: false,
      locale: process.env.VUE_APP_I18N_LOCALE || 'en',
      fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
      messages: this.loadLocaleMessages(),
    });
  }

  /**
   * Load locale messages
   *
   * The load…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@albe2669
Comment options

Answer selected by albe2669
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant