diff --git a/packages/ludic.i18n/keyed_render.ludic b/packages/ludic.i18n/keyed_render.ludic index 825a4ae9..7795d1ad 100644 --- a/packages/ludic.i18n/keyed_render.ludic +++ b/packages/ludic.i18n/keyed_render.ludic @@ -51,7 +51,7 @@ function kr_fill(i18n_st: mut I18nState, t: string, args: []string) -> string { if h >= 1 { var v = "" if h < len(args) { v = args[h] } - if i18n_is_key(v) { v = keyed(i18n_st, v) } + if i18n_is_key(v) { v = keyed(i18n_st, v) } else if i18n_st.on and kr_words(v) { v = L(i18n_st, v) } r = r + t[seg..i] + v i = hole_end(t, i) seg = i @@ -62,6 +62,13 @@ function kr_fill(i18n_st: mut I18nState, t: string, args: []string) -> string { return r + t[seg..len(t)] } +# an argument with letters in it (not a number, a time, a sign): while the game still hands English +# into a key's holes (until its code and data are keys, phase 26.9), it gets the old English lookup +function kr_words(s: string) -> bool { + for i in 0 .. len(s) { if (s[i] >= 65 and s[i] <= 90) or (s[i] >= 97 and s[i] <= 122) { return true } } + return false +} + # a count written as decimal digits (a leading - allowed); anything else is 0 function kr_int(s: string) -> int { var v = 0 diff --git a/packages/ludic.i18n/tests/keys_test.ludic b/packages/ludic.i18n/tests/keys_test.ludic index a7be6db0..6a69995a 100644 --- a/packages/ludic.i18n/tests/keys_test.ludic +++ b/packages/ludic.i18n/tests/keys_test.ludic @@ -21,7 +21,7 @@ program I18nKeysTest { function tt() -> string { var s = "msgid \"\"\nmsgstr \"\"\n\"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : 2);\\n\"\n\n" s = s + po_line("pause.resume", "Devam") + po_line("hud.day", "{1}. Gun") + po_line("species.elk.a_name", "bir geyik") - s = s + po_line("catch.saw", "{2} saatinde {1} gordun.") + po_line("Settings", "Ayarlar") + s = s + po_line("catch.saw", "{2} saatinde {1} gordun.") + po_line("Settings", "Ayarlar") + po_line("Day {1}", "{1}. gun") return s + plural("pack.items", "{1} esya", "{1} esyaa", "{1} esyalar") } function start (i18n_st: mut I18nState) -> void { @@ -74,4 +74,13 @@ program I18nKeysTest { expect(L(i18n_st, tr(k"pause.resume")) == "Devam") expect(not i18n_is_key("Settings") and i18n_is_key(i18n_key("x")) and i18n_is_key(i18n_key_plural("x"))) } + + test "an English value handed into a key's hole still gets its old English line, until it is a key itself" (i18n_st: mut I18nState) { + start(i18n_st) + expect(L(i18n_st, trf(k"catch.saw", "Settings", "5:30", "", "")) == "You saw Settings at 5:30.") + i18n_load_text(i18n_st, tt()) + expect(L(i18n_st, trf(k"catch.saw", "Settings", "5:30", "", "")) == "5:30 saatinde Ayarlar gordun.") # exact + expect(L(i18n_st, trf(k"catch.saw", "Day 3", "5:30", "", "")) == "5:30 saatinde 3. gun gordun.") # a pattern + expect(L(i18n_st, trf(k"catch.saw", "Nowhere known", "7", "", "")) == "7 saatinde Nowhere known gordun.") # no line: as it is + } }