translation handling
Closed this issue · 2 comments
Hi,
I am trying to create custom translations in primo explore. I have some questions about this:
-
What is the way to do this? Where i can add custom translations?
-
How to get existing translations via javascript for custom components (I am only see examples with html template) ?
I have tried something like this:
var translateModule = angular.injector(['ng', 'prmTranslate']);
translateModule.get('PrmTranslationIdToCodeMapping');
translate.getMapping('...');
In debugging session i can see translation adds with setMapping function. When i get
the other way and want to get translations for id that was set with help of setMapping('...'), I am getting always an undefinied value. Is this the correct way to do it ?
Thank you for some advice.
Best regards, Paul
For the second question I have found a way with $translate to get existing translations:
/*
* get md tab item labels
*/
var queryResult = parent[0].querySelector('md-pagination-wrapper');
var injector = angular.element(parent[0]).injector();
var $translate = injector.get("$translate");
var tr1 = $translate.instant("fulldisplay.command.RISPushTo");
Best regards, Paul
Hi Paul,
I am not sure what the best practice is, but here is what I do.
-
I add a new entry for each translation mapping into one of the code tables through the Primo Back Office.
-
I inject the
$translate
service into my controller and attach a callback to the promise returned by$translate()
as follows. The promise seems to resolve with the translation label itself if there is no mapping for it.angular.module('viewCustom').controller('myController', [ '$translate', function($translate) { var ctrl = this; ctrl.$onInit = function() { let result; $translate('eshelf.signin.title').then(function(translation) { result = translation; }); console.log(result); }; } ]);
Regards,
Murat