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!("bg"),
translation!("ca"),
translation!("cs"),
translation!("da"),
translation!("de"),
translation!("el"),
translation!("en"),
translation!("es"),
translation!("et"),
@ -28,7 +29,6 @@ const TRANSLATIONS: [(&str, &str); 40] = [
translation!("fi"),
translation!("fr"),
translation!("gl"),
translation!("el"),
translation!("he"),
translation!("hu"),
translation!("id"),
@ -41,8 +41,8 @@ const TRANSLATIONS: [(&str, &str); 40] = [
translation!("nl"),
translation!("nn"),
translation!("pl"),
translation!("pt-PT"),
translation!("pt"),
translation!("pt-PT"),
translation!("ro"),
translation!("ru"),
translation!("sl"),
@ -53,8 +53,8 @@ const TRANSLATIONS: [(&str, &str); 40] = [
translation!("tr"),
translation!("uk"),
translation!("vi"),
translation!("zh-TW"),
translation!("zh"),
translation!("zh-TW"),
];
/// An identifier for a natural language.
@ -312,14 +312,74 @@ fn lang_str(lang: Lang, region: Option<Region>) -> EcoString {
#[cfg(test)]
mod tests {
use std::collections::HashSet;
use std::path::PathBuf;
use typst_utils::option_eq;
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]
fn test_region_option_eq() {
let region = Some(Region([b'U', b'S']));
assert!(option_eq(region, "US"));
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 = الفصل
outline = المحتويات
raw = قائمة
page = صفحة
page = صفحة

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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