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

Documentation suggestion #300

Open
jeremy-holt opened this issue Feb 15, 2019 · 2 comments
Open

Documentation suggestion #300

jeremy-holt opened this issue Feb 15, 2019 · 2 comments

Comments

@jeremy-holt
Copy link

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
Copy link

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
Copy link
Member

zewa666 commented Feb 16, 2019

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

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

No branches or pull requests

3 participants