Project

diacriti_x

0.0
The project is in a healthy, maintained state
Determines which letter in a Vietnamese word should receive accent marks, and provides IME input methods (VNI) for typing Vietnamese.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 1.1
 Project Readme

DiacritiX

CI Gem Version

A Ruby gem for Vietnamese diacritics. It solves two problems:

  1. Accent placement — determines which letter in a Vietnamese word should receive the accent mark (e.g., in "ngoay", the accent goes on the "a")
  2. IME input — transforms numeric-suffixed text into accented Vietnamese using the VNI input method

Why?

Vietnamese accent placement follows specific rules based on vowel combinations and consonant pairs. This gem encodes those rules so you don't have to.

Installation

gem install diacriti_x

Or add to your Gemfile:

gem 'diacriti_x'

Usage

As a library

require 'diacriti_x'

# Find which letter gets the accent
result = DiacritiX::Accentifier.call('ngoay')
result.success? # => true
result.result   # => 3 (index of 'a')

# Transform VNI input into Vietnamese
vni = DiacritiX::IME::VNI.new
vni.call('Viet65 Nam')  # => "Việt Nam"
vni.call('toi1')        # => "tói"
vni.call('di9')         # => "đi"

VNI key mapping

Key Diacritic Example
1 Acute (á) a1á
2 Grave (à) a2à
3 Hook above (ả) a3
4 Tilde (ã) a4ã
5 Dot below (ạ) a5
6 Circumflex (â) a6â
7 Horn (ư, ơ) u7ư
8 Breve (ă) a8ă
9 Đ stroke d9đ

CLI

# Highlight which letter receives the accent
accentify "ngoay"
# => ngo[a]y (the 'a' is highlighted in green)

# Transform VNI input into Vietnamese
ruby bin/ime/vni "Vie6t5 Nam"
# => Việt Nam

Accent placement rules

The Accentifier applies rules in priority order — first match wins:

  1. Special Vietnamese vowels — ơ, ư always take the accent
  2. Vietnamese vowels — ă, â, ê, ô take priority over plain Latin vowels
  3. Vowel pairs — in oa, oe, oo, uy, ươ the second vowel gets it
  4. Consonant pairs — after gi, qu the accent goes on the next vowel
  5. Fallback — first vowel found

Development

git clone https://github.com/DiDi035/DiacritiX.git
cd DiacritiX
bundle install
bundle exec rake test
bundle exec rubocop