Preserve current AVIF compression, local voice pipelines, practice workflows, UI API migration, locale updates, and packaging work. Native integration validation remains pending.
139 lines
4.4 KiB
Ziran
139 lines
4.4 KiB
Ziran
#import, file "../src/app/locale.zi";
|
|
#import, file "../src/app/assets.zi";
|
|
#import, file "../src/app/locale_preferences.zi";
|
|
#import "locale_parser";
|
|
#import "locale_policy";
|
|
|
|
VerifyCatalog :: (code: string) -> bool {
|
|
if !LocaleUse(code) {
|
|
return false
|
|
}
|
|
active := LocaleAssetForCode(code)
|
|
english := AssetRead("locales/en.txt")
|
|
if !active.found || !english.found {
|
|
return false
|
|
}
|
|
// Root packages also update older wrappers whose guide still requests
|
|
// these messages. They must retain translated text in every catalog.
|
|
if LocaleText("launcher_guide_manage") == "launcher_guide_manage" ||
|
|
LocaleText("launcher_guide_profile") == "launcher_guide_profile" {
|
|
return false
|
|
}
|
|
// Compare every shipped key against the uncached parser. This catches
|
|
// collisions, multiline values, Unicode, and language switch invalidation.
|
|
cursor: s32 = 0
|
|
checked: s32 = 0
|
|
while cursor < cast(s32)english.data.count {
|
|
line := LocaleNextLine(english.data, cursor)
|
|
cursor = line.next
|
|
if line.end - line.start > 2 &&
|
|
english.data[line.start] == cast(u8)91 &&
|
|
english.data[line.end - 1] == cast(u8)93 {
|
|
key := english.data[line.start + 1:line.end - 1]
|
|
expected := LocaleResolveCatalog(active.data, english.data, key)
|
|
if LocaleText(key) != expected {
|
|
return false
|
|
}
|
|
checked += 1
|
|
}
|
|
}
|
|
return checked > 600
|
|
}
|
|
|
|
#program_export
|
|
Answer :: () -> s32 {
|
|
if app_locale_preferences() != LocaleSystemPreferences() {
|
|
return 99
|
|
}
|
|
if LocaleLanguageCount() != 10 {
|
|
return -1
|
|
}
|
|
english := LocaleLanguageAt(0)
|
|
spanish := LocaleLanguageAt(1)
|
|
if english.code != "en" || english.label != "English" ||
|
|
spanish.code != "es" || spanish.label != "Español" {
|
|
return -2
|
|
}
|
|
if LocaleLanguageAt(10).code.count != 0 ||
|
|
LocaleActiveCode() != "en" || LocaleText("close_button") != "Close" {
|
|
return -3
|
|
}
|
|
if !LocaleUse("es") || LocaleActiveCode() != "es" ||
|
|
LocaleText("close_button") != "Cerrar" {
|
|
return -4
|
|
}
|
|
if LocaleUse("../secrets") || LocaleActiveCode() != "es" ||
|
|
LocaleText("missing_locale_key") != "missing_locale_key" {
|
|
return -5
|
|
}
|
|
if !LocaleUse("en") || LocaleText("close_button") != "Close" {
|
|
return -6
|
|
}
|
|
if LocaleSupports("id") || LocaleSupports("it") ||
|
|
LocaleUse("id") || LocaleUse("it") || LocaleActiveCode() != "en" {
|
|
return -10
|
|
}
|
|
if !LocaleSupports("pt") || !LocaleUse("pt") || LocaleActiveCode() != "pt" ||
|
|
LocaleText("close_button") != "Fechar" || !LocaleUse("en") {
|
|
return -11
|
|
}
|
|
if LocalePreferred("es_AR.UTF-8") != "es" ||
|
|
LocalePreferred("xx:ja_JP.UTF-8") != "ja" ||
|
|
LocalePreferred("xx") != "en" ||
|
|
LocalePreferred("id_ID:it_IT") != "en" ||
|
|
LocalePreferred("pt_BR:en_US") != "pt" ||
|
|
LocalePreferred(LocaleSystemPreferences()) != "es" {
|
|
return -8
|
|
}
|
|
for index: 0..LocaleLanguageCount() - 1 {
|
|
if !VerifyCatalog(LocaleLanguageAt(index).code) {
|
|
return -7
|
|
}
|
|
}
|
|
if !VerifyProviderChanges() {
|
|
return -9
|
|
}
|
|
return 42
|
|
}
|
|
|
|
provider_ready: bool;
|
|
|
|
DelayedCatalog :: (path: string) -> AssetView {
|
|
if path == "locales/en.txt" {
|
|
return AssetView.{.found = true,
|
|
.data = ifx provider_ready then "[close_button]\nClose from app\n---\n" else ""}
|
|
}
|
|
return AssetView.{}
|
|
}
|
|
|
|
ReplacementCatalog :: (path: string) -> AssetView {
|
|
if path == "locales/en.txt" {
|
|
return AssetView.{.found = true, .data = "[close_button]\nUpdated from app\n---\n"}
|
|
}
|
|
return AssetView.{}
|
|
}
|
|
|
|
VerifyProviderChanges :: () -> bool {
|
|
if !LocaleUse("en") || LocaleText("close_button") != "Close" {
|
|
return false
|
|
}
|
|
provider_ready = false
|
|
AssetBindProvider(DelayedCatalog)
|
|
if LocaleText("close_button") != "close_button" {
|
|
return false
|
|
}
|
|
// An early lookup can happen before the provider has mounted its root.
|
|
// The same provider becoming ready must recover without changing language.
|
|
provider_ready = true
|
|
if LocaleText("close_button") != "Close from app" {
|
|
return false
|
|
}
|
|
AssetBindProvider(ReplacementCatalog)
|
|
if LocaleText("close_button") != "Updated from app" {
|
|
return false
|
|
}
|
|
AssetUnbindProvider()
|
|
return LocaleText("close_button") == "Close"
|
|
}
|
|
#import, file "../src/app/host_services.zi";
|