aurelia / i18n

A plugin that provides i18n support.
MIT License
93 stars 70 forks source link

Documentation suggestion #300

Open jeremy-holt opened 5 years ago

jeremy-holt commented 5 years ago

The documentation at https://aurelia.io/docs/plugins/i18n#installing-the-plugin at Registering the Plugin - using the i18next-xhr-backend using the aurelia-cli loader should be clearer.....

Using aurelia-cli 1.0.0-beta.13

  1. ONLY install aurelia-i18n and i18next-xhr-backend. DO NOT install i18next.

  2. ONLY use the i18next-xhr-backend Backend

main.ts should look something like

import { Aurelia } from "aurelia-framework";
import { TCustomAttribute } from "aurelia-i18n";
import { PLATFORM } from "aurelia-pal";
import Bluebird from "bluebird";
import "bootstrap";
import Backend from "i18next-xhr-backend";

export async function configure(aurelia: Aurelia) {
  aurelia.use
    .standardConfiguration()
    .plugin(PLATFORM.moduleName("aurelia-dialog"))
    .plugin(PLATFORM.moduleName("aurelia-validation"))

    .plugin("aurelia-i18n", instance => {
      const aliases = ["t", "i18n"];

      TCustomAttribute.configureAliases(aliases);

      instance.i18next.use(Backend);

      instance.i18next.on("languageChanged", lng => {
        moment.locale(lng);
      });

      return instance.setup({
        backend: {
          loadPath: "./locales/{{lng}}/{{ns}}.json"
        },
        attributes: aliases,
        lng: "en",
        fallbackLng: "en",
        debug: true
      });
    })
    .feature(PLATFORM.moduleName("resources/index"));

  aurelia.use.developmentLogging(environment.debug ? "debug" : "warn");

  if (environment.testing) {
    aurelia.use.plugin(PLATFORM.moduleName("aurelia-testing"));
  }

  await aurelia.start();
  return aurelia.setRoot(PLATFORM.moduleName("app"));
}

and in aurelia.json

    "copyFiles": {
      "src/locales/en/*": "wwwroot/locales/en",
      "src/locales/fr/*":"wwwroot/locales/fr"      
    },

If you're trying to get it to work with the aurelia-cli/alameda the example at Copy translation files for webpack and i18next-xhr-backend is misleading.

khuongduybui commented 5 years ago

Or you can just use plugin.i18next.use(Backend.with(aurelia.loader)); I only needed to install aurelia-i18n and nothing else. I don't need to copy anything either.

zewa666 commented 5 years ago

@jeremy-holt if you could create a PR it would be easier to follow the actual edits.