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.

Update b-table column labels when switching display language

See original GitHub issue

The solution provided in #1687 doesn’t seem to work anymore. I’ve put fields as a function into the computed area and I’m calling a method, which returns the column name. When I change the language by calling this.$i18n.i18next.changeLanguage(locale), it changes everything but the table header. Sometimes, they don’t change at all, and sometimes they get replaced with the translation path. The error sometimes fixed itself after hitting F5.

When adding a console.log to the getColLabel method, I can see, that it is not called when updating the language.

I’m using vue-i18next in combination with backend loading:

computed: {
  fields() {
	return [
	  {
		key: 'article',
		label: this.getColLabel('article')
	  },
	  {
		key: 'typeCode',
		label: this.getColLabel('typeCode')
	  },
	  // ...
	];
  }
},
methods: {
  getColLabel(colName) {
    return this.$i18n.t('yourApplication.affectedProducts.table.columns.' + colName);
  }
}
import i18next from 'i18next';
import VueI18Next from '@panter/vue-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import XHR from 'i18next-xhr-backend';
import YAML from 'js-yaml';

Vue.use(VueI18Next);

i18next
  .use(XHR)
  .use(LanguageDetector)
  .init({
    ns: ['main', 'order'],
    defaultNS: 'order',
    fallbackLng: 'en',
    backend: {
      loadPath: '/locales/{{lng}}/{{ns}}.yaml',
      parse: data => YAML.safeLoad(data)
    }
  });

const i18n = new VueI18Next(i18next);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  i18n,
  router,
  template: '<App/>',
  components: {
    App
  }
})

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
tmorehousecommented, May 31, 2019

Convert your computed property to method to force it to be called each render (as long as changing the language will cause your app/component to re-render). Vue caches the results of computed properties, and only updates them when reactive data changes them. Although this method will be called anytime something triggers the table to re-render (so its not very efficient)

Another solution is to read in a reactive prop (that specifies your language has changed) at the top of the computed prop (i.e. assign it to a const). This will ensure that the computed prop is re-evaluated by Vue each time the language changes. i.e.:

{
  // ...
  computed: {
    fields() {
      // Accessing this.$i18n.locale in this computed prop tells Vue that
      // this computed prop should update whenever this.$i18n.locale
      // changes it value, even though we don't use the value.
      const lang = this.$i18n.locale
      // We add the following just so that minification optimizers
      // do not remove the above statement because the return value isn't used.
      if (!lang) { return [] }
      // Return the array of translated values
      return [
        { key: 'article', label: this.getColLabel('article') },
	{ key: 'typeCode', label: this.getColLabel('typeCode') },
	  // ...
	]
    }
  }
1reaction
tmorehousecommented, Jun 17, 2019

They must have not set this.$i18n.i18next.language to be an observable (i.e. reactive) in i18next.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change axis labels in a chart in Office - Microsoft Support
Right-click the category labels to change, and click Select Data. Right-click the category axis and Select Data · In Horizontal (Category) Axis Labels,...
Read more >
How to Relabel Rows and Columns in an R Table
Method 1 - Specify all labels · 1. Select your R table. · 2. In the object inspector, go to Properties > R...
Read more >
Dynamically changing the language of columns labels in VueJS
If I go to one of the other pages and comeback to the table, the labels and placeholders are updated correctly.
Read more >
Refresh breaks due to COLUMN NAME CHANGES? 3 ways to ...
... column name change in the data source can break a power query refresh. It can be really frustrating that just by renaming...
Read more >
How to rename columns in Power Query that ... - YouTube
It is not uncommon having to deal with reports with column headers related to dates that change each time we get new data....
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