Skip to content

translit

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

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

Signature

translit(
    sourceText: string,
    ruleName?: string,
    rulesToUse?: TranslitRule | TranslitRulePhase[] | TranslitRuleItem[],
    userOptions?: { [option: string]: boolean | string },
    trace?: boolean): Observable<TranslitResult>

Parameters

  • sourceText - Input string to convert.
  • ruleName - The rule name to load and cache rule.
  • rulesToUse - One-time transliterate rules to use.
  • userOptions - The options user selected to check with 'when' rule options.
  • trace - Flag to include conversion trace information in the result.

Returns

Returns the Observable<TranslitResult> object if there is no validtion or parsing error.

TranslitResult

/**
 * The transliteration result interface.
 */
export interface TranslitResult {
    /**
     * The converted output text.
     */
    outputText: string;
    /**
     * The value will be 'true' if source text is converted or replaced.
     */
    replaced?: boolean;
    /**
     * Conversion duration in miliseconds.
     */
    duration?: number;
    /**
     * Conversion information for debugging.
     */
    traces?: TranslitTraceInfo[];
}

TranslitTraceInfo

 /**
  * Conversion trace information.
  */
export interface TranslitTraceInfo {
    /**
     * The description of applied rule item information.
     */
    description: string;
    /**
     * The 'from' text of rule item.
     */
    from: string;
    /**
     * The 'to' text of rule item.
     */
    to?: string;
    /**
     * The matched string.
     */
    matchedText: string;
    /**
     * The previous string.
     */
    previousText: string;
    /**
     * The replaced string.
     */
    replacedText: string;
}

Throws

Throws either TranslitParseError or Error instance if there is any parsing error or validation error.