tflori / angular-translator

translation module for angular
https://tflori.github.io/angular-translator/
MIT License
21 stars 6 forks source link

Implement Modules #11

Closed tflori closed 7 years ago

tflori commented 7 years ago

A module is a subset of translations. The idea is to store translations in different files and load them when you enter this module. For example you need only text for managing your own content but when you enter the administration area you may need additional text like "CHANGE_USER_QUOTA".

Basically it should be configurable in the TranslateConfig:

import {TranslateConfig, TranslateLoaderJson} from 'angular2-translator';

export const translateConfig = new TranslateConfig({
  defaultLang: 'de',
  providedLangs: ['de', 'en'],
  loader: TranslateLoaderJson,
  loaderConfig: {
    path: 'i18n',
    extension: '-lang.json'
  },
  modules: {
    'admin': {
      path: '{{parent}}/admin',    // default
      extension: '{{parent}}',     // default
    },
    'messages': {} // use defaults
  }
});

To use the module from TranslateService:

import {Component} from "angular2/core";
import {TranslateService} from "angular2-translator";

@Component({
    selector: "my-app",
    template: "<h1>{{ title }}</h1"
})
export class ChangeQuotaComponent {
    public title = 'CHANGE_USER_QUOTA';

    constructor(translate: TranslateService) {
        translate.module('admin')
            .translate(this.title)
            .then((title) => this.title = title);
    }
}

There is still a question how to use the module from component and pipe. I think we will have two options: add this parameter as translate-module="admin" or define it in the component or even in a parent component (I don't know if this is possible).

tflori commented 7 years ago

how to define what we get from parent? maybe another loader gets different parameters?

i think translateserve should not know anything about the configuration itself. it is :any and therefore it does not know what is inside.