move underscores into generated code

This commit is contained in:
llama 2025-09-27 00:28:13 +08:00
parent df743d2633
commit 8246581d46
No known key found for this signature in database
GPG key ID: 0B7543854B9413C3
4 changed files with 11 additions and 11 deletions

View file

@ -10,6 +10,6 @@ pub struct All;
include!(concat!(env!("OUT_DIR"), "/strings.rs"));
impl Translations for All {
const _STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &STRINGS;
const _KEYS_BY_MODULE: &[&[&str]] = &KEYS_BY_MODULE;
const STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &_STRINGS;
const KEYS_BY_MODULE: &[&[&str]] = &_KEYS_BY_MODULE;
}

View file

@ -10,6 +10,6 @@ pub struct Launcher;
include!(concat!(env!("OUT_DIR"), "/strings_launcher.rs"));
impl Translations for Launcher {
const _STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &STRINGS;
const _KEYS_BY_MODULE: &[&[&str]] = &KEYS_BY_MODULE;
const STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &_STRINGS;
const KEYS_BY_MODULE: &[&[&str]] = &_KEYS_BY_MODULE;
}

View file

@ -191,8 +191,8 @@ fn get_bundle_with_extra(
}
pub trait Translations {
const _STRINGS: &phf::Map<&str, &phf::Map<&str, &str>>;
const _KEYS_BY_MODULE: &[&[&str]];
const STRINGS: &phf::Map<&str, &phf::Map<&str, &str>>;
const KEYS_BY_MODULE: &[&[&str]];
}
#[derive(Clone)]
@ -203,7 +203,7 @@ pub struct I18n<P: Translations = All> {
impl<P: Translations> I18n<P> {
fn get_key(module_idx: usize, translation_idx: usize) -> &'static str {
P::_KEYS_BY_MODULE
P::KEYS_BY_MODULE
.get(module_idx)
.and_then(|translations| translations.get(translation_idx))
.cloned()
@ -217,7 +217,7 @@ impl<P: Translations> I18n<P> {
.map(|lang| {
let mut buf = String::new();
let lang_name = remapped_lang_name(&lang);
if let Some(strings) = P::_STRINGS.get(lang_name) {
if let Some(strings) = P::STRINGS.get(lang_name) {
if desired_modules.is_empty() {
// empty list, provide all modules
for value in strings.values() {
@ -240,7 +240,7 @@ impl<P: Translations> I18n<P> {
/// either access each &str separately, or load them on demand.
fn ftl_localized_text(lang: &LanguageIdentifier) -> Option<String> {
let lang = remapped_lang_name(lang);
if let Some(module) = P::_STRINGS.get(lang) {
if let Some(module) = P::STRINGS.get(lang) {
let mut text = String::new();
for module_text in module.values() {
text.push_str(module_text)

View file

@ -144,7 +144,7 @@ fn write_translation_key_index(modules: &[Module], buf: &mut String) {
writeln!(
buf,
"pub(crate) const KEYS_BY_MODULE: [&[&str]; {count}] = [",
"pub(crate) const _KEYS_BY_MODULE: [&[&str]; {count}] = [",
count = modules.len(),
)
.unwrap();
@ -164,7 +164,7 @@ fn write_translation_key_index(modules: &[Module], buf: &mut String) {
fn write_lang_map(map: &TranslationsByLang, buf: &mut String) {
buf.push_str(
"
pub(crate) const STRINGS: phf::Map<&str, &phf::Map<&str, &str>> = phf::phf_map! {
pub(crate) const _STRINGS: phf::Map<&str, &phf::Map<&str, &str>> = phf::phf_map! {
",
);