# -*- coding: utf-8 -*-
from hangulize import *


class Vietnamese(Language):
    """For transcribing Vietnamese."""

    __iso639__ = {1: 'vi', 2: 'vie', 3: 'vie'}
    __tmp__ = 'X'

    vowels = 'aAeEioOuUy'
    notation = Notation([
        ('ă',         'A'),
        ('â',         'O'),
        ('đ',         'D'),
        ('ê',         'E'),
        ('ơ',         'O'),
        ('ư',         'U'),
        ('ch',         'C'),
        ('c',          'k'),
        ('j',          'd'),
        ('kh{@}',      'K'),
        ('ngh{e|E|i}', 'N'),
        ('ng',         'N'),
        ('nh{@}',      'nY'),
        ('anh',        'ain'),
        ('nh',         'n'),
        ('gi',         'd'),
        ('gh',         'g'),
        ('ph{@}',      'f'),
        ('qua',        'kWa'),
        ('q',          'k'),
        ('th{@}',      'T'),
        ('tr',         'C'),
        ('dz{@}',      'd'),
        ('z{@}',       'd'),
        ('ia',         'iO'),
        ('ya',         'yO'),
        ('ua',         'uO'),
        ('Ua',         'UO'),
        ('A',          'a'),
        ('y{@}',       'Y'),
        ('y',          'i'), # bl, br, bn, dr, kl, kr, pl, pr, hr rc, 
        ('C{@}',       'XC'),
        ('{@}C',       'CX'),
        ('^k',         'Xk'),
        ('k{@|l|r|W}', 'Xk'),
        ('{@}k',       'kX'),
        ('m{@}',       'Xm'),
        ('{@}m',       'mX'),
        ('n{@|Y}',     'Xn'),
        ('{@}n',       'nX'),
        ('N',          'NX'),
        ('^p',         'Xp'),
        ('p{@|l|r}',   'Xp'),
        ('{@}p',       'pX'),
        ('^t',         'Xt'),
        ('t{@|l}',     'Xt'),
        ('{@}t',       'tX'),
        ('^l',         Choseong(L)),
        ('{X}l{@}',    Choseong(L)),
        ('l{@}',       Jongseong(L), Choseong(L)),
        ('l',          Jongseong(L)),
        ('b',          Choseong(B)),
        ('XC',         Choseong(JJ)),
        ('CX',         Jongseong(G)),
        ('C',          Choseong(JJ)),
        ('d',          Choseong(J)),
        ('D',          Choseong(D)),
        ('f',          Choseong(P)),
        ('g',          Choseong(G)),
        ('h{@}',       Choseong(H)),
        ('Xk',         Choseong(GG)),
        ('kX',         Jongseong(G)),
        ('k',          Choseong(GG)),
        ('K',          Choseong(K)),
        ('Xm',         Choseong(M)),
        ('mX',         Jongseong(M)),
        ('Xn',         Choseong(N)),
        ('nX',         Jongseong(N)),
        ('NX',         Jongseong(NG)),
        ('Xp',         Choseong(BB)),
        ('pX',         Jongseong(B)),
        ('p',          Choseong(BB)),
        ('r',          Choseong(L)),
        ('s',          Choseong(S)),
        ('Xt',         Choseong(DD)),
        ('tX',         Jongseong(S)),
        ('t',          Choseong(DD)),
        ('T',          Choseong(T)),
        ('v',          Choseong(B)),
        ('x',          Choseong(SS)),
        ('z',          Choseong(K)),
        ('Wa',         Jungseong(WA)),
        ('Ya',         Jungseong(YA)),
        ('Ye',         Jungseong(YAE)),
        ('YE',         Jungseong(YE)),
        ('Yi',         Jungseong(I)),
        ('Yo',         Jungseong(YO)),
        ('YO',         Jungseong(YEO)),
        ('Yu',         Jungseong(YU)),
        ('YU',         Jungseong(YU)),
        ('a',          Jungseong(A)),
        ('e',          Jungseong(AE)),
        ('E',          Jungseong(E)),
        ('i',          Jungseong(I)),
        ('o',          Jungseong(O)),
        ('O',          Jungseong(EO)),
        ('u',          Jungseong(U)),
        ('U',          Jungseong(EU)),
    ])

    def normalize(self, string):
        return normalize_roman(string, {
            'Ă': 'ă', 'Ằ': 'ă', 'ằ': 'ă', 'Ẳ': 'ă', 'ẳ': 'ă',
            'Ẵ': 'ă', 'ẵ': 'ă', 'Ắ': 'ă', 'ắ': 'ă', 'Ặ': 'ă',
            'ặ': 'ă', 'Â': 'â', 'Ầ': 'â', 'ầ': 'â', 'Ẩ': 'â',
            'ẩ': 'â', 'Ẫ': 'â', 'ẫ': 'â', 'Ấ': 'â', 'ấ': 'â',
            'Ậ': 'â', 'ậ': 'â', 'Đ': 'đ', 'Ê': 'ê', 'Ề': 'ê',
            'ề': 'ê', 'Ể': 'ê', 'ể': 'ê', 'Ễ': 'ê', 'ễ': 'ê',
            'Ế': 'ê', 'ế': 'ê', 'Ệ': 'ê', 'ệ': 'ê', 'Ơ': 'ơ',
            'Ờ': 'ơ', 'ờ': 'ơ', 'Ở': 'ơ', 'ở': 'ơ', 'Ỡ': 'ơ',
            'ỡ': 'ơ', 'Ớ': 'ơ', 'ớ': 'ơ', 'Ợ': 'ơ', 'ợ': 'ơ',
            'Ư': 'ư', 'Ừ': 'ư', 'ừ': 'ư', 'Ử': 'ư', 'ử': 'ư',
            'Ữ': 'ư', 'ữ': 'ư', 'Ứ': 'ư', 'ứ': 'ư', 'Ự': 'ư',
            'ự': 'ư'
        })


__lang__ = Vietnamese
