1.0.0 • Published 5 years ago

@myanmartools/ng-translit v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

Build Status Build status

Transliteration Core Package for Angular

Gitter

Transliteration core service package for Angular applications which can be used in font encodings conversion such as Zawgyi to Myanmar Unicode.

Features

  • Transliterate rules can be loaded dynamically or statically (lazily or eagerly) using custom TranslitRuleLoader
  • Extendable TranslitRuleLoader (see built-in HttpTranslitRuleLoader for implementation demo)
  • Latest Angular versions are supported
  • Compatible with Angular Universal (Server Side Rendering - SSR)

Get Started

Installation

npm

npm install @myanmartools/ng-translit

or yarn

yarn add @myanmartools/ng-translit

Module Setup (app.module.ts)

import { TranslitModule } from '@myanmartools/ng-translit';
import { HttpTranslitRuleLoaderModule } from '@myanmartools/ng-translit/http-loader';

export function translitEndpointFactory(baseUrl: string, sourceEnc: string, targetEnc: string): string {
    const prefix = sourceEnc === 'zg' ? 'zawgyi-to-unicode-rules/' : 'unicode-to-zawgyi-rules/';

    return `${baseUrl}${prefix}${sourceEnc}2${targetEnc}.json`;
}

@NgModule({
    imports: [
        // Other module imports

        // ng-translit
        TranslitModule,
        HttpTranslitRuleLoaderModule.withOptions({
            baseUrl: 'https://raw.githubusercontent.com/myanmartools/zawgyi-unicode-translit-rules/master/rules/',
            endpointFactory: translitEndpointFactory
        })
    ]
})
export class AppModule { }

Usage (app.component.ts)

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

import { TranslitService } from '@myanmartools/ng-translit';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
    sourceEnc = 'zg';
    targetEnc = 'uni';

    constructor(private readonly _translitService: TranslitService) {
        this._translitService.translit('ျမန္မာစာ', this.sourceEnc, this.targetEnc)
            .subscribe(result => {
                // output: မြန်မာစာ
                console.log('output: ', result.outputText);
            });
    }
}

Installing Translit Rules Locally (Optional)

Transliterate rules can be installed locally, for example, to install Zawgyi Unicode conversion rules:

npm install @myanmartools/zawgyi-unicode-translit-rules

Example

Demo - demo Angular application for ng-translit

Real-word Application - Zawgyi Unicode Converter

Zawgyi Unicode Converter

Zawgyi Unicode Converter is an Angular Progress Web Application (PWA) designed to detect & convert Myanmar font encodings between Zawgyi-One and Unicode.

Related Projects

These are some other repos for related projects:

Myanmar Tools Website

Myanmar Tools Website

https://myanmartools.org

A list of open source projects for Myanmar specific software applications, libraries, productivity utilities, language, script, Unicode and font tools.

Feedback and Contributing

Check out the Contributing page to see the best places to log issues and start discussions.

License

This repository is licensed with the MIT license.