Check that all translation files are added to TRANSLATIONS and ends with newline (#6424)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
Ilia 2025-06-12 13:30:53 +03:00 committed by GitHub
parent 46d57b00b5
commit bd41fb9427
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 108 additions and 48 deletions

View File

@ -14,13 +14,14 @@ macro_rules! translation {
}; };
} }
const TRANSLATIONS: [(&str, &str); 40] = [ const TRANSLATIONS: &[(&str, &str)] = &[
translation!("ar"), translation!("ar"),
translation!("bg"), translation!("bg"),
translation!("ca"), translation!("ca"),
translation!("cs"), translation!("cs"),
translation!("da"), translation!("da"),
translation!("de"), translation!("de"),
translation!("el"),
translation!("en"), translation!("en"),
translation!("es"), translation!("es"),
translation!("et"), translation!("et"),
@ -28,7 +29,6 @@ const TRANSLATIONS: [(&str, &str); 40] = [
translation!("fi"), translation!("fi"),
translation!("fr"), translation!("fr"),
translation!("gl"), translation!("gl"),
translation!("el"),
translation!("he"), translation!("he"),
translation!("hu"), translation!("hu"),
translation!("id"), translation!("id"),
@ -41,8 +41,8 @@ const TRANSLATIONS: [(&str, &str); 40] = [
translation!("nl"), translation!("nl"),
translation!("nn"), translation!("nn"),
translation!("pl"), translation!("pl"),
translation!("pt-PT"),
translation!("pt"), translation!("pt"),
translation!("pt-PT"),
translation!("ro"), translation!("ro"),
translation!("ru"), translation!("ru"),
translation!("sl"), translation!("sl"),
@ -53,8 +53,8 @@ const TRANSLATIONS: [(&str, &str); 40] = [
translation!("tr"), translation!("tr"),
translation!("uk"), translation!("uk"),
translation!("vi"), translation!("vi"),
translation!("zh-TW"),
translation!("zh"), translation!("zh"),
translation!("zh-TW"),
]; ];
/// An identifier for a natural language. /// An identifier for a natural language.
@ -312,14 +312,74 @@ fn lang_str(lang: Lang, region: Option<Region>) -> EcoString {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::collections::HashSet;
use std::path::PathBuf;
use typst_utils::option_eq; use typst_utils::option_eq;
use super::*; use super::*;
fn translation_files_iter() -> impl Iterator<Item = PathBuf> {
std::fs::read_dir("translations")
.unwrap()
.map(|e| e.unwrap().path())
.filter(|e| e.is_file() && e.extension().is_some_and(|e| e == "txt"))
}
#[test] #[test]
fn test_region_option_eq() { fn test_region_option_eq() {
let region = Some(Region([b'U', b'S'])); let region = Some(Region([b'U', b'S']));
assert!(option_eq(region, "US")); assert!(option_eq(region, "US"));
assert!(!option_eq(region, "AB")); assert!(!option_eq(region, "AB"));
} }
#[test]
fn test_all_translations_included() {
let defined_keys =
HashSet::<&str>::from_iter(TRANSLATIONS.iter().map(|(lang, _)| *lang));
let mut checked = 0;
for file in translation_files_iter() {
assert!(
defined_keys.contains(
file.file_stem()
.expect("translation file should have basename")
.to_str()
.expect("translation file name should be utf-8 encoded")
),
"translation from {:?} should be registered in TRANSLATIONS in {}",
file.file_name().unwrap(),
file!(),
);
checked += 1;
}
assert_eq!(TRANSLATIONS.len(), checked);
}
#[test]
fn test_all_translation_files_formatted() {
for file in translation_files_iter() {
let content = std::fs::read_to_string(&file)
.expect("translation file should be in utf-8 encoding");
let filename = file.file_name().unwrap();
assert!(
content.ends_with('\n'),
"translation file {filename:?} should end with linebreak",
);
for line in content.lines() {
assert_eq!(
line.trim(),
line,
"line {line:?} in {filename:?} should not have extra whitespaces"
);
}
}
}
#[test]
fn test_translations_sorted() {
assert!(
TRANSLATIONS.is_sorted_by_key(|(lang, _)| lang),
"TRANSLATIONS should be sorted"
);
}
} }

View File

@ -5,4 +5,4 @@ bibliography = المراجع
heading = الفصل heading = الفصل
outline = المحتويات outline = المحتويات
raw = قائمة raw = قائمة
page = صفحة page = صفحة

View File

@ -5,4 +5,4 @@ bibliography = Библиография
heading = Раздел heading = Раздел
outline = Съдържание outline = Съдържание
raw = Приложение raw = Приложение
page = стр. page = стр.

View File

@ -5,4 +5,4 @@ bibliography = Bibliografia
heading = Secció heading = Secció
outline = Índex outline = Índex
raw = Llistat raw = Llistat
page = pàgina page = pàgina

View File

@ -5,4 +5,4 @@ bibliography = Bibliografie
heading = Kapitola heading = Kapitola
outline = Obsah outline = Obsah
raw = Výpis raw = Výpis
page = strana page = strana

View File

@ -5,4 +5,4 @@ bibliography = Bibliografi
heading = Afsnit heading = Afsnit
outline = Indhold outline = Indhold
raw = Liste raw = Liste
page = side page = side

View File

@ -5,4 +5,4 @@ bibliography = Bibliographie
heading = Abschnitt heading = Abschnitt
outline = Inhaltsverzeichnis outline = Inhaltsverzeichnis
raw = Listing raw = Listing
page = Seite page = Seite

View File

@ -4,4 +4,4 @@ equation = Εξίσωση
bibliography = Βιβλιογραφία bibliography = Βιβλιογραφία
heading = Κεφάλαιο heading = Κεφάλαιο
outline = Περιεχόμενα outline = Περιεχόμενα
raw = Παράθεση raw = Παράθεση

View File

@ -5,4 +5,4 @@ bibliography = Bibliography
heading = Section heading = Section
outline = Contents outline = Contents
raw = Listing raw = Listing
page = page page = page

View File

@ -5,4 +5,4 @@ bibliography = Bibliografía
heading = Sección heading = Sección
outline = Índice outline = Índice
raw = Listado raw = Listado
page = página page = página

View File

@ -5,4 +5,4 @@ bibliography = Viited
heading = Peatükk heading = Peatükk
outline = Sisukord outline = Sisukord
raw = List raw = List
page = lk. page = lk.

View File

@ -5,4 +5,4 @@ bibliography = Viitteet
heading = Osio heading = Osio
outline = Sisällys outline = Sisällys
raw = Esimerkki raw = Esimerkki
page = sivu page = sivu

View File

@ -5,4 +5,4 @@ bibliography = Bibliographie
heading = Chapitre heading = Chapitre
outline = Table des matières outline = Table des matières
raw = Liste raw = Liste
page = page page = page

View File

@ -5,4 +5,4 @@ bibliography = Bibliografía
heading = Sección heading = Sección
outline = Índice outline = Índice
raw = Listado raw = Listado
page = páxina page = páxina

View File

@ -5,4 +5,4 @@ bibliography = רשימת מקורות
heading = חלק heading = חלק
outline = תוכן עניינים outline = תוכן עניינים
raw = קטע מקור raw = קטע מקור
page = עמוד page = עמוד

View File

@ -4,5 +4,5 @@ equation = Egyenlet
bibliography = Irodalomjegyzék bibliography = Irodalomjegyzék
heading = Fejezet heading = Fejezet
outline = Tartalomjegyzék outline = Tartalomjegyzék
# raw = # raw =
page = oldal page = oldal

View File

@ -5,4 +5,4 @@ bibliography = Heimildaskrá
heading = Kafli heading = Kafli
outline = Efnisyfirlit outline = Efnisyfirlit
raw = Sýnishorn raw = Sýnishorn
page = blaðsíða page = blaðsíða

View File

@ -5,4 +5,4 @@ bibliography = Bibliografia
heading = Sezione heading = Sezione
outline = Indice outline = Indice
raw = Codice raw = Codice
page = pag. page = pag.

View File

@ -5,4 +5,4 @@ bibliography = 参考文献
heading = 節 heading = 節
outline = 目次 outline = 目次
raw = リスト raw = リスト
page = ページ page = ページ

View File

@ -5,4 +5,4 @@ bibliography = Conspectus librorum
heading = Caput heading = Caput
outline = Index capitum outline = Index capitum
raw = Exemplum raw = Exemplum
page = charta page = charta

View File

@ -5,4 +5,4 @@ bibliography = Bibliografi
heading = Kapittel heading = Kapittel
outline = Innhold outline = Innhold
raw = Utskrift raw = Utskrift
page = side page = side

View File

@ -5,4 +5,4 @@ bibliography = Bibliografie
heading = Hoofdstuk heading = Hoofdstuk
outline = Inhoudsopgave outline = Inhoudsopgave
raw = Listing raw = Listing
page = pagina page = pagina

View File

@ -5,4 +5,4 @@ bibliography = Bibliografi
heading = Kapittel heading = Kapittel
outline = Innhald outline = Innhald
raw = Utskrift raw = Utskrift
page = side page = side

View File

@ -5,4 +5,4 @@ bibliography = Bibliografia
heading = Sekcja heading = Sekcja
outline = Spis treści outline = Spis treści
raw = Program raw = Program
page = strona page = strona

View File

@ -1,8 +1,8 @@
# figure = # figure =
# table = # table =
# equation = # equation =
# bibliography = # bibliography =
heading = Secção heading = Secção
outline = Índice outline = Índice
# raw = # raw =
page = página page = página

View File

@ -5,4 +5,4 @@ bibliography = Bibliografia
heading = Seção heading = Seção
outline = Sumário outline = Sumário
raw = Listagem raw = Listagem
page = página page = página

View File

@ -6,4 +6,4 @@ heading = Secțiunea
outline = Cuprins outline = Cuprins
# may be wrong # may be wrong
raw = Listă raw = Listă
page = pagina page = pagina

View File

@ -5,4 +5,4 @@ bibliography = Библиография
heading = Раздел heading = Раздел
outline = Содержание outline = Содержание
raw = Листинг raw = Листинг
page = с. page = с.

View File

@ -5,4 +5,4 @@ bibliography = Literatura
heading = Poglavje heading = Poglavje
outline = Kazalo outline = Kazalo
raw = Program raw = Program
page = stran page = stran

View File

@ -5,4 +5,4 @@ bibliography = Bibliografi
heading = Kapitull heading = Kapitull
outline = Përmbajtja outline = Përmbajtja
raw = List raw = List
page = faqe page = faqe

View File

@ -5,4 +5,4 @@ bibliography = Литература
heading = Поглавље heading = Поглавље
outline = Садржај outline = Садржај
raw = Програм raw = Програм
page = страна page = страна

View File

@ -5,4 +5,4 @@ bibliography = Bibliografi
heading = Kapitel heading = Kapitel
outline = Innehåll outline = Innehåll
raw = Listing raw = Listing
page = sida page = sida

View File

@ -5,4 +5,4 @@ bibliography = Bibliograpiya
heading = Seksyon heading = Seksyon
outline = Talaan ng mga Nilalaman outline = Talaan ng mga Nilalaman
raw = Listahan raw = Listahan
# page = # page =

View File

@ -5,4 +5,4 @@ bibliography = Kaynakça
heading = Bölüm heading = Bölüm
outline = İçindekiler outline = İçindekiler
raw = Liste raw = Liste
page = sayfa page = sayfa

View File

@ -5,4 +5,4 @@ bibliography = Бібліографія
heading = Розділ heading = Розділ
outline = Зміст outline = Зміст
raw = Лістинг raw = Лістинг
page = c. page = c.

View File

@ -6,4 +6,4 @@ heading = Phần
outline = Mục lục outline = Mục lục
# may be wrong # may be wrong
raw = Chương trình raw = Chương trình
page = trang page = trang

View File

@ -1,8 +1,8 @@
figure = 圖 figure = 圖
# table = # table =
equation = 式 equation = 式
bibliography = 書目 bibliography = 書目
heading = 小節 heading = 小節
outline = 目錄 outline = 目錄
raw = 程式 raw = 程式
# page = # page =

View File

@ -5,4 +5,4 @@ bibliography = 参考文献
heading = 小节 heading = 小节
outline = 目录 outline = 目录
raw = 代码 raw = 代码
# page = # page =