This page covers a next version of Handsontable, and is not published yet.

This page covers a non-latest version of Handsontable.

# Language change in Angular

# Overview

The following example is an implementation of the @handsontable/angular component with an option to change the Context Menu language.

Select a language from the selector above the table and open the Context Menu to see the result.

# Example

// app.component.ts
import { Component } from '@angular/core';
import { getLanguagesDictionaries } from 'handsontable/i18n';
import { createSpreadsheetData } from './helpers';

@Component({
  selector: 'app-root',
  template: `
  <label for="languages">Select language:</label>
  <select [(ngModel)]="language">
    <option *ngFor="let l of languages" [value]="l.languageCode">{{l.languageCode}}</option>
  </select><br/><br/>
  <div>
    <hot-table [language]="language" [settings]="hotSettings"></hot-table>
  </div>
  `,
})
class AppComponent {
  hotSettings: Handsontable.GridSettings = {
    data: createSpreadsheetData(5, 10),
    colHeaders: true,
    rowHeaders: true,
    contextMenu: true,
    height: 'auto',
    licenseKey: 'non-commercial-and-evaluation'
  };
  language = 'en-US';
  languages = getLanguagesDictionaries();
}

// app.module.ts
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { HotTableModule } from '@handsontable/angular';
import { registerAllModules } from 'handsontable/registry';

// register Handsontable's modules
registerAllModules();

@NgModule({
  imports:      [ BrowserModule, FormsModule, HotTableModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
class AppModule { }

// bootstrap
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

platformBrowserDynamic().bootstrapModule(AppModule).catch(err => { console.error(err) });