question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dynamically change translation

See original GitHub issue

I’d like to know if there is any way to dynamically change translations ?

I’ve tried using $.extend the language, then picker.render(true), it doesn’t work.

thanks in advance

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
liitfrcommented, Apr 13, 2017

+1. I’ve found a workaround to make it reactive on meteor, here is the trick :

Template.formNewShift.onRendered(function formNewShiftOnRendered() {
  const $input = this.$('.datepicker').pickadate({
    selectMonths: true,
    selectYears: 2,
    format: TAPi18n.__('components.pickadate.format'),
    closeOnSelect: true,
    closeOnClear: true,
    max: new Date(),
    onSet(ele) {
      if (ele.select) {
        this.close();
      }
    },
  });
  const picker = $input.pickadate('picker');
  this.autorun(() => {
    picker.component.settings.monthsFull = _.map(TAPi18n.__('components.pickadate.monthsFull', { returnObjectTrees: true }), month => month);
    picker.component.settings.monthsShort = _.map(TAPi18n.__('components.pickadate.monthsShort', { returnObjectTrees: true }), month => month);
    picker.component.settings.weekdaysFull = _.map(TAPi18n.__('components.pickadate.weekdaysFull', { returnObjectTrees: true }), weekday => weekday);
    picker.component.settings.weekdaysShort = _.map(TAPi18n.__('components.pickadate.weekdaysShort', { returnObjectTrees: true }), weekday => weekday);
    picker.component.settings.today = TAPi18n.__('components.pickadate.today');
    picker.component.settings.clear = TAPi18n.__('components.pickadate.clear');
    picker.component.settings.close = TAPi18n.__('components.pickadate.close');
    picker.component.settings.firstDay = TAPi18n.__('components.pickadate.firstDay');
    picker.component.settings.format = TAPi18n.__('components.pickadate.format');
    picker.component.settings.labelMonthNext = TAPi18n.__('components.pickadate.labelMonthNext');
    picker.component.settings.labelMonthPrev = TAPi18n.__('components.pickadate.labelMonthPrev');
    picker.component.settings.labelMonthSelect = TAPi18n.__('components.pickadate.labelMonthSelect');
    picker.component.settings.labelYearSelect = TAPi18n.__('components.pickadate.labelYearSelect');
    picker.render();
  });
});

That said, I can read about component in API doc that :

This is the picker’s relative component constructor that builds the date or time picker. This API is in flux – so avoid using it for now.

Did you find a better solution ?

0reactions
Cerealkillerwaycommented, Apr 18, 2017

I use the same method in my meteor apps: a template-level autorun loop to update the UI with translated strings;

more than that, I also set again the value to translate also the value shown in the input box: this.pickerInstance.set('select', value, {options});

(assuming “value” is the actual value of the input box)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Translations in Angular - Christian Lüdemann
Creating an Angular app with dynamic translations from a REST API · Setting up translations on the Node server · Use translations in...
Read more >
How to translate dynamic content? - Help Center
In this article, you'll find how to translate dynamic content. 1) Head over to your site and right-click to pull up the menu...
Read more >
I cannot dynamically change language in Angular
Original angular multilanguage support doesn't allow you to change language dynamically. The only thing you could do is to generate projects ...
Read more >
Dynamic Translation - Product Documentation | ServiceNow
Dynamic Translation for Agent Chat (DTAC) translates chat conversations from one language to another. This translating enables agents and ...
Read more >
Dynamic translations in Angular made possible - Medium
Dynamic translations in Angular made possible ... support splitting up a single language (update: in fact, ngx-translate supports this).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found