Skip to content

TranslitService

Moe Myat Zaw edited this page Jun 7, 2019 · 1 revision

The TranslitService class is a core transliteration service for swapping letters from one script to another.

Public Methods

The translit method is a main method to convert source text to targeted text using transliteration rules.

The loadRule method is used to load and cache rule by name early. If the rule already in cache and 'refresh' is false, then returns the cached rule.

Example

import { Component } from '@angular/core';

import { TranslitRuleItem, TranslitService } from '@dagonmetric/ng-translit';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  constructor(private readonly _translitService: TranslitService) {
    const zg2uniRules: TranslitRuleItem[] = [{
      from: '\u103B([\u1000-\u1021])',
      to: '$1\u103C'
    },
    {
      from: '\u1039',
      to: '\u103A'
    }];

    this._translitService.translit('ျမန္မာစာ', 'zg2uni', zg2uniRules)
      .subscribe(result => {
        // output: မြန်မာစာ
        console.log('output: ', result.outputText);
      });
  }
}