module

Krikri::PluginHelpers::LocaleGenCommand

LocaleGenCommand - the pure string logic of community.general.locale_gen, split out of the plugin so the normalization table, the /usr/share/i18n/SUPPORTED entry matcher and the /etc/locale.gen rewrite are unit-testable without a Debian host (or a locales package). The plugin executes the commands these build on (locale -a, locale-gen).

Constants

LOCALE_NORMALIZATION = {".utf8" => ".UTF-8", ".eucjp" => ".EUC-JP", ".iso885915" => ".ISO-8859-15", ".cp1251" => ".CP1251", ".koi8r" => ".KOI8-R", ".armscii8" => ".ARMSCII-8", ".euckr" => ".EUC-KR", ".gbk" => ".GBK", ".gb18030" => ".GB18030", ".euctw" => ".EUC-TW"}

Real module's LOCALE_NORMALIZATION: locale -a reports encodings in either case (en_US.utf8 vs en_US.UTF-8), so both sides of every comparison pass through this table first.

SUPPORTED_ENTRY_RE = /^\s*#?\s*(?<locale>\S+[._\S]+) (?<charset>\S+)\s*$/

A /usr/share/i18n/SUPPORTED entry line, e.g. "en_US.UTF-8 UTF-8" or a commented "# de_LI.UTF-8 UTF-8". Mirrors the real module's re_locale_entry, including that the locale group is \S+[._\S]+ - the trailing charset is whatever follows the LAST space the backtracking engine can still hand to it.

Class methods

changed?(state : String, all_present : Bool, check_mode : Bool) : Bool

changed determination: the real module tracks state_tracking - whether ALL requested locales are present - against the requested state, so present changes when any locale is missing, but absent only changes (and only applies) when every requested locale is present. Check mode never applies, and StateModuleHelper recomputes state_tracking from the untouched system, so check mode always reports changed=False.

Source
fix_case(name : String) : String
Source
locale_available?(locale : String, supported_lines : Array(String), locale_a_output : String) : Bool

assert_available: a requested locale must appear as an entry in one of the SUPPORTED files, OR already be compiled (listed by locale -a - covers e.g. C.UTF-8, which some systems don't list in SUPPORTED). Comparison goes through fix_case on both sides.

Source
rewrite_locale_gen(lines : Array(String), names : Array(String), enabled : Bool) : Array(String)

set_locale_glibc: comment out (enabled: false) or uncomment (enabled: true) one entry per requested locale in /etc/locale.gen, preserving each line's charset column. Real module's regex is ^#?\s*<name> (?P<charset>.+); it applies the sub to every line, and a line that doesn't match is returned unchanged - which is also what makes this idempotent (an already-enabled line matches and rewrites to itself).

Source
supported_entry_locale(line : String) : String | Nil
Source