Skip to content

Change the default language of the context menu from English to any of the built-in translations, using the language property.

Example - Select language

The following example implements the @handsontable/vue3 component with the option to change the Context Menu language configured. Select a language from the selector above the table and open the Context Menu to see the result.

Find out which Vue 3 versions are supported

  • {{ lang }}
JavaScript
import { defineComponent } from 'vue';
import { HotTable } from '@handsontable/vue3';
import {
registerLanguageDictionary,
getLanguagesDictionaries,
arAR,
csCZ,
deCH,
deDE,
esMX,
frFR,
hrHR,
itIT,
jaJP,
koKR,
lvLV,
nbNO,
nlNL,
plPL,
ptBR,
ruRU,
srSP,
zhCN,
zhTW
} from 'handsontable/i18n';
import { registerAllModules } from 'handsontable/registry';
registerLanguageDictionary(arAR);
registerLanguageDictionary(csCZ);
registerLanguageDictionary(deCH);
registerLanguageDictionary(deDE);
registerLanguageDictionary(esMX);
registerLanguageDictionary(frFR);
registerLanguageDictionary(hrHR);
registerLanguageDictionary(itIT);
registerLanguageDictionary(jaJP);
registerLanguageDictionary(koKR);
registerLanguageDictionary(lvLV);
registerLanguageDictionary(nbNO);
registerLanguageDictionary(nlNL);
registerLanguageDictionary(plPL);
registerLanguageDictionary(ptBR);
registerLanguageDictionary(ruRU);
registerLanguageDictionary(srSP);
registerLanguageDictionary(zhCN);
registerLanguageDictionary(zhTW);
// register Handsontable's modules
registerAllModules();
const ExampleComponent = defineComponent({
data() {
return {
hotSettings: {
data: [
['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1', 'I1', 'J1'],
['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'J2'],
['A3', 'B3', 'C3', 'D3', 'E3', 'F3', 'G3', 'H3', 'I3', 'J3'],
['A4', 'B4', 'C4', 'D4', 'E4', 'F4', 'G4', 'H4', 'I4', 'J4'],
['A5', 'B5', 'C5', 'D5', 'E5', 'F5', 'G5', 'H5', 'I5', 'J5'],
],
colHeaders: true,
rowHeaders: true,
contextMenu: true,
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
licenseKey: 'non-commercial-and-evaluation'
},
language: 'en-US',
isOpen: false,
languages: [],
};
},
mounted() {
this.languages = getLanguagesDictionaries().map((d) => d.languageCode);
document.addEventListener('click', this.handleClickOutside);
document.addEventListener('keydown', this.handleEscape);
},
beforeUnmount() {
document.removeEventListener('click', this.handleClickOutside);
document.removeEventListener('keydown', this.handleEscape);
},
methods: {
toggleDropdown() {
this.isOpen = !this.isOpen;
},
selectLanguage(lang) {
this.language = lang;
this.isOpen = false;
},
handleClickOutside(e) {
if (this.$refs.dropdown && !this.$refs.dropdown.contains(e.target)) {
this.isOpen = false;
}
},
handleEscape(e) {
if (e.key === 'Escape') {
this.isOpen = false;
}
},
},
components: {
HotTable,
}
});
export default ExampleComponent;
HTML
<div id="example1" class="select-language">
<div class="example-controls-container">
<div class="controls">
<label>Select language of the context menu:</label>
<div class="theme-dropdown" ref="dropdown">
<button
class="theme-dropdown-trigger"
type="button"
aria-haspopup="listbox"
:aria-expanded="isOpen"
@click="toggleDropdown"
>
<span>{{ language }}</span>
<svg class="theme-dropdown-chevron" aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6l6 -6"/></svg>
</button>
<ul class="theme-dropdown-menu" role="listbox" v-if="isOpen">
<li
v-for="lang in languages"
:key="lang"
role="option"
:aria-selected="language === lang"
@click="selectLanguage(lang)"
>{{ lang }}</li>
</ul>
</div>
</div>
</div>
<hot-table :language="language" :settings="hotSettings"></hot-table>
</div>

Related guides

Configuration options

Core methods

Hooks