Core: The params for translations are ignored

Created on 27 Sep 2018  路  1Comment  路  Source: ngx-translate/core

Current behavior

The params for translations are ignored.

Expected behavior

Params values should be added into the translation.

How do you think that we should fix this?

No idea.

Minimal reproduction of the problem with instructions

Forked ngx-translate demo from GitHub readme to reproduce https://stackblitz.com/edit/github-a35qvr

Environment

ngx-translate version: 10.0.1
Angular version: 6.0.0

Browser:
any

Most helpful comment

For now I'm using this function to apply the prams to the translations:

export function applyParamsToTranslation(trans: string, params: Object): string {
  // TODO add err handling
  function getTransParamNames(text: string): Array<string> {
    return text.match(/{{\s*[\w\.]+\s*}}/g).map(function(bracedParam) {
      return bracedParam.match(/[\w\.]+/)[0];
    });
  }
  const keys = getTransParamNames(trans);
  for (let i = 0; i < keys.length; i++) {
    if (params[keys[i]]) {
      trans = trans.replace(keys[i], params[keys[i]]);
    }
  }
  return trans.replace(/{{|}}/g, '');
}

>All comments

For now I'm using this function to apply the prams to the translations:

export function applyParamsToTranslation(trans: string, params: Object): string {
  // TODO add err handling
  function getTransParamNames(text: string): Array<string> {
    return text.match(/{{\s*[\w\.]+\s*}}/g).map(function(bracedParam) {
      return bracedParam.match(/[\w\.]+/)[0];
    });
  }
  const keys = getTransParamNames(trans);
  for (let i = 0; i < keys.length; i++) {
    if (params[keys[i]]) {
      trans = trans.replace(keys[i], params[keys[i]]);
    }
  }
  return trans.replace(/{{|}}/g, '');
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

madoublet picture madoublet  路  3Comments

dankerk picture dankerk  路  3Comments

bjornharvold picture bjornharvold  路  3Comments

webprofusion-chrisc picture webprofusion-chrisc  路  4Comments

pndewit picture pndewit  路  3Comments