mirror of
https://github.com/typst/typst
synced 2025-06-15 16:46:24 +08:00
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:
parent
46d57b00b5
commit
bd41fb9427
@ -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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,4 @@ bibliography = المراجع
|
||||
heading = الفصل
|
||||
outline = المحتويات
|
||||
raw = قائمة
|
||||
page = صفحة
|
||||
page = صفحة
|
||||
|
@ -5,4 +5,4 @@ bibliography = Библиография
|
||||
heading = Раздел
|
||||
outline = Съдържание
|
||||
raw = Приложение
|
||||
page = стр.
|
||||
page = стр.
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografia
|
||||
heading = Secció
|
||||
outline = Índex
|
||||
raw = Llistat
|
||||
page = pàgina
|
||||
page = pàgina
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografie
|
||||
heading = Kapitola
|
||||
outline = Obsah
|
||||
raw = Výpis
|
||||
page = strana
|
||||
page = strana
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografi
|
||||
heading = Afsnit
|
||||
outline = Indhold
|
||||
raw = Liste
|
||||
page = side
|
||||
page = side
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliographie
|
||||
heading = Abschnitt
|
||||
outline = Inhaltsverzeichnis
|
||||
raw = Listing
|
||||
page = Seite
|
||||
page = Seite
|
||||
|
@ -4,4 +4,4 @@ equation = Εξίσωση
|
||||
bibliography = Βιβλιογραφία
|
||||
heading = Κεφάλαιο
|
||||
outline = Περιεχόμενα
|
||||
raw = Παράθεση
|
||||
raw = Παράθεση
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliography
|
||||
heading = Section
|
||||
outline = Contents
|
||||
raw = Listing
|
||||
page = page
|
||||
page = page
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografía
|
||||
heading = Sección
|
||||
outline = Índice
|
||||
raw = Listado
|
||||
page = página
|
||||
page = página
|
||||
|
@ -5,4 +5,4 @@ bibliography = Viited
|
||||
heading = Peatükk
|
||||
outline = Sisukord
|
||||
raw = List
|
||||
page = lk.
|
||||
page = lk.
|
||||
|
@ -5,4 +5,4 @@ bibliography = Viitteet
|
||||
heading = Osio
|
||||
outline = Sisällys
|
||||
raw = Esimerkki
|
||||
page = sivu
|
||||
page = sivu
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliographie
|
||||
heading = Chapitre
|
||||
outline = Table des matières
|
||||
raw = Liste
|
||||
page = page
|
||||
page = page
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografía
|
||||
heading = Sección
|
||||
outline = Índice
|
||||
raw = Listado
|
||||
page = páxina
|
||||
page = páxina
|
||||
|
@ -5,4 +5,4 @@ bibliography = רשימת מקורות
|
||||
heading = חלק
|
||||
outline = תוכן עניינים
|
||||
raw = קטע מקור
|
||||
page = עמוד
|
||||
page = עמוד
|
||||
|
@ -4,5 +4,5 @@ equation = Egyenlet
|
||||
bibliography = Irodalomjegyzék
|
||||
heading = Fejezet
|
||||
outline = Tartalomjegyzék
|
||||
# raw =
|
||||
page = oldal
|
||||
# raw =
|
||||
page = oldal
|
||||
|
@ -5,4 +5,4 @@ bibliography = Heimildaskrá
|
||||
heading = Kafli
|
||||
outline = Efnisyfirlit
|
||||
raw = Sýnishorn
|
||||
page = blaðsíða
|
||||
page = blaðsíða
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografia
|
||||
heading = Sezione
|
||||
outline = Indice
|
||||
raw = Codice
|
||||
page = pag.
|
||||
page = pag.
|
||||
|
@ -5,4 +5,4 @@ bibliography = 参考文献
|
||||
heading = 節
|
||||
outline = 目次
|
||||
raw = リスト
|
||||
page = ページ
|
||||
page = ページ
|
||||
|
@ -5,4 +5,4 @@ bibliography = Conspectus librorum
|
||||
heading = Caput
|
||||
outline = Index capitum
|
||||
raw = Exemplum
|
||||
page = charta
|
||||
page = charta
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografi
|
||||
heading = Kapittel
|
||||
outline = Innhold
|
||||
raw = Utskrift
|
||||
page = side
|
||||
page = side
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografie
|
||||
heading = Hoofdstuk
|
||||
outline = Inhoudsopgave
|
||||
raw = Listing
|
||||
page = pagina
|
||||
page = pagina
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografi
|
||||
heading = Kapittel
|
||||
outline = Innhald
|
||||
raw = Utskrift
|
||||
page = side
|
||||
page = side
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografia
|
||||
heading = Sekcja
|
||||
outline = Spis treści
|
||||
raw = Program
|
||||
page = strona
|
||||
page = strona
|
||||
|
@ -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
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografia
|
||||
heading = Seção
|
||||
outline = Sumário
|
||||
raw = Listagem
|
||||
page = página
|
||||
page = página
|
||||
|
@ -6,4 +6,4 @@ heading = Secțiunea
|
||||
outline = Cuprins
|
||||
# may be wrong
|
||||
raw = Listă
|
||||
page = pagina
|
||||
page = pagina
|
||||
|
@ -5,4 +5,4 @@ bibliography = Библиография
|
||||
heading = Раздел
|
||||
outline = Содержание
|
||||
raw = Листинг
|
||||
page = с.
|
||||
page = с.
|
||||
|
@ -5,4 +5,4 @@ bibliography = Literatura
|
||||
heading = Poglavje
|
||||
outline = Kazalo
|
||||
raw = Program
|
||||
page = stran
|
||||
page = stran
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografi
|
||||
heading = Kapitull
|
||||
outline = Përmbajtja
|
||||
raw = List
|
||||
page = faqe
|
||||
page = faqe
|
||||
|
@ -5,4 +5,4 @@ bibliography = Литература
|
||||
heading = Поглавље
|
||||
outline = Садржај
|
||||
raw = Програм
|
||||
page = страна
|
||||
page = страна
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliografi
|
||||
heading = Kapitel
|
||||
outline = Innehåll
|
||||
raw = Listing
|
||||
page = sida
|
||||
page = sida
|
||||
|
@ -5,4 +5,4 @@ bibliography = Bibliograpiya
|
||||
heading = Seksyon
|
||||
outline = Talaan ng mga Nilalaman
|
||||
raw = Listahan
|
||||
# page =
|
||||
# page =
|
||||
|
@ -5,4 +5,4 @@ bibliography = Kaynakça
|
||||
heading = Bölüm
|
||||
outline = İçindekiler
|
||||
raw = Liste
|
||||
page = sayfa
|
||||
page = sayfa
|
||||
|
@ -5,4 +5,4 @@ bibliography = Бібліографія
|
||||
heading = Розділ
|
||||
outline = Зміст
|
||||
raw = Лістинг
|
||||
page = c.
|
||||
page = c.
|
||||
|
@ -6,4 +6,4 @@ heading = Phần
|
||||
outline = Mục lục
|
||||
# may be wrong
|
||||
raw = Chương trình
|
||||
page = trang
|
||||
page = trang
|
||||
|
@ -1,8 +1,8 @@
|
||||
figure = 圖
|
||||
# table =
|
||||
# table =
|
||||
equation = 式
|
||||
bibliography = 書目
|
||||
heading = 小節
|
||||
outline = 目錄
|
||||
raw = 程式
|
||||
# page =
|
||||
# page =
|
||||
|
@ -5,4 +5,4 @@ bibliography = 参考文献
|
||||
heading = 小节
|
||||
outline = 目录
|
||||
raw = 代码
|
||||
# page =
|
||||
# page =
|
||||
|
Loading…
x
Reference in New Issue
Block a user