mirror of
https://github.com/ankitects/anki.git
synced 2025-11-07 13:17:12 -05:00
move underscores into generated code
This commit is contained in:
parent
df743d2633
commit
8246581d46
4 changed files with 11 additions and 11 deletions
|
|
@ -10,6 +10,6 @@ pub struct All;
|
||||||
include!(concat!(env!("OUT_DIR"), "/strings.rs"));
|
include!(concat!(env!("OUT_DIR"), "/strings.rs"));
|
||||||
|
|
||||||
impl Translations for All {
|
impl Translations for All {
|
||||||
const _STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &STRINGS;
|
const STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &_STRINGS;
|
||||||
const _KEYS_BY_MODULE: &[&[&str]] = &KEYS_BY_MODULE;
|
const KEYS_BY_MODULE: &[&[&str]] = &_KEYS_BY_MODULE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,6 @@ pub struct Launcher;
|
||||||
include!(concat!(env!("OUT_DIR"), "/strings_launcher.rs"));
|
include!(concat!(env!("OUT_DIR"), "/strings_launcher.rs"));
|
||||||
|
|
||||||
impl Translations for Launcher {
|
impl Translations for Launcher {
|
||||||
const _STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &STRINGS;
|
const STRINGS: &phf::Map<&str, &phf::Map<&str, &str>> = &_STRINGS;
|
||||||
const _KEYS_BY_MODULE: &[&[&str]] = &KEYS_BY_MODULE;
|
const KEYS_BY_MODULE: &[&[&str]] = &_KEYS_BY_MODULE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,8 +191,8 @@ fn get_bundle_with_extra(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Translations {
|
pub trait Translations {
|
||||||
const _STRINGS: &phf::Map<&str, &phf::Map<&str, &str>>;
|
const STRINGS: &phf::Map<&str, &phf::Map<&str, &str>>;
|
||||||
const _KEYS_BY_MODULE: &[&[&str]];
|
const KEYS_BY_MODULE: &[&[&str]];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -203,7 +203,7 @@ pub struct I18n<P: Translations = All> {
|
||||||
|
|
||||||
impl<P: Translations> I18n<P> {
|
impl<P: Translations> I18n<P> {
|
||||||
fn get_key(module_idx: usize, translation_idx: usize) -> &'static str {
|
fn get_key(module_idx: usize, translation_idx: usize) -> &'static str {
|
||||||
P::_KEYS_BY_MODULE
|
P::KEYS_BY_MODULE
|
||||||
.get(module_idx)
|
.get(module_idx)
|
||||||
.and_then(|translations| translations.get(translation_idx))
|
.and_then(|translations| translations.get(translation_idx))
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
@ -217,7 +217,7 @@ impl<P: Translations> I18n<P> {
|
||||||
.map(|lang| {
|
.map(|lang| {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
let lang_name = remapped_lang_name(&lang);
|
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() {
|
if desired_modules.is_empty() {
|
||||||
// empty list, provide all modules
|
// empty list, provide all modules
|
||||||
for value in strings.values() {
|
for value in strings.values() {
|
||||||
|
|
@ -240,7 +240,7 @@ impl<P: Translations> I18n<P> {
|
||||||
/// either access each &str separately, or load them on demand.
|
/// either access each &str separately, or load them on demand.
|
||||||
fn ftl_localized_text(lang: &LanguageIdentifier) -> Option<String> {
|
fn ftl_localized_text(lang: &LanguageIdentifier) -> Option<String> {
|
||||||
let lang = remapped_lang_name(lang);
|
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();
|
let mut text = String::new();
|
||||||
for module_text in module.values() {
|
for module_text in module.values() {
|
||||||
text.push_str(module_text)
|
text.push_str(module_text)
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ fn write_translation_key_index(modules: &[Module], buf: &mut String) {
|
||||||
|
|
||||||
writeln!(
|
writeln!(
|
||||||
buf,
|
buf,
|
||||||
"pub(crate) const KEYS_BY_MODULE: [&[&str]; {count}] = [",
|
"pub(crate) const _KEYS_BY_MODULE: [&[&str]; {count}] = [",
|
||||||
count = modules.len(),
|
count = modules.len(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -164,7 +164,7 @@ fn write_translation_key_index(modules: &[Module], buf: &mut String) {
|
||||||
fn write_lang_map(map: &TranslationsByLang, buf: &mut String) {
|
fn write_lang_map(map: &TranslationsByLang, buf: &mut String) {
|
||||||
buf.push_str(
|
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! {
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue