Update b-table column labels when switching display language
See original GitHub issueThe 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:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.:
They must have not set
this.$i18n.i18next.language
to be an observable (i.e. reactive) ini18next
.