Merge pull request #17711 from Snuffleupagus/importl10n-Fetch-API

Use the Fetch API to download the l10n files
This commit is contained in:
Jonas Jenwald 2024-03-08 11:51:34 +01:00 committed by GitHub
commit b14f696071
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 119 additions and 67 deletions

View File

@ -14,7 +14,6 @@
*/
import fs from "fs";
import https from "https";
import path from "path";
// Fetches all languages that have an *active* translation in mozilla-central.
@ -22,47 +21,34 @@ import path from "path";
const DEFAULT_LOCALE = "en-US";
const EXCLUDE_LANG_CODES = ["ca-valencia", "ja-JP-mac"];
const EXCLUDE_LANG_CODES = new Set(["ca-valencia", "ja-JP-mac"]);
function normalizeText(s) {
return s.replaceAll(/\r\n?/g, "\n").replaceAll("\uFEFF", "");
}
function downloadLanguageCodes() {
async function downloadLanguageCodes() {
console.log("Downloading language codes...\n");
const ALL_LOCALES =
"https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/locales/all-locales";
return new Promise(function (resolve) {
https.get(ALL_LOCALES, function (response) {
if (response.statusCode === 200) {
let content = "";
response.setEncoding("utf8");
response.on("data", function (chunk) {
content += chunk;
});
response.on("end", function () {
content = content.trim(); // Remove any leading/trailing white-space.
const langCodes = normalizeText(content).split("\n");
const response = await fetch(ALL_LOCALES);
if (!response.ok) {
throw new Error(response.statusText);
}
const content = await response.text();
// Remove any leading/trailing white-space.
const langCodes = normalizeText(content.trim()).split("\n");
// Remove all locales that we don't want to download below.
for (const langCode of [DEFAULT_LOCALE, ...EXCLUDE_LANG_CODES]) {
const i = langCodes.indexOf(langCode);
if (i > -1) {
langCodes.splice(i, 1);
}
}
resolve(langCodes);
});
} else {
resolve([]);
}
});
});
return langCodes.filter(
langCode => langCode !== DEFAULT_LOCALE && !EXCLUDE_LANG_CODES.has(langCode)
);
}
function downloadLanguageFiles(root, langCode) {
console.log("Downloading " + langCode + "...");
async function downloadLanguageFiles(root, langCode) {
console.log(`Downloading ${langCode}...`);
// Constants for constructing the URLs. Translations are taken from the
// Nightly channel as those are the most recent ones.
@ -71,41 +57,27 @@ function downloadLanguageFiles(root, langCode) {
// Defines which files to download for each language.
const files = ["viewer.ftl"];
let downloadsLeft = files.length;
const outputDir = path.join(root, langCode);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
return new Promise(function (resolve) {
// Download the necessary files for this language.
files.forEach(function (fileName) {
for (const fileName of files) {
const outputPath = path.join(outputDir, fileName);
const url =
MOZ_CENTRAL_ROOT + langCode + MOZ_CENTRAL_PDFJS_DIR + fileName;
const url = MOZ_CENTRAL_ROOT + langCode + MOZ_CENTRAL_PDFJS_DIR + fileName;
https.get(url, function (response) {
const response = await fetch(url);
if (!response.ok) {
// Not all files exist for each language. Files without translations
// have been removed (https://bugzilla.mozilla.org/show_bug.cgi?id=1443175).
if (response.statusCode === 200) {
let content = "";
response.setEncoding("utf8");
response.on("data", function (chunk) {
content += chunk;
});
response.on("end", function () {
continue;
}
const content = await response.text();
fs.writeFileSync(outputPath, normalizeText(content), "utf8");
if (--downloadsLeft === 0) {
resolve();
}
});
} else if (--downloadsLeft === 0) {
resolve();
}
});
});
});
}
async function downloadL10n(root) {

View File

@ -274,6 +274,9 @@ pdfjs-editor-free-text-button-label = Testenn
pdfjs-editor-ink-button =
.title = Tresañ
pdfjs-editor-ink-button-label = Tresañ
pdfjs-editor-stamp-button =
.title = Ouzhpennañ pe aozañ skeudennoù
pdfjs-editor-stamp-button-label = Ouzhpennañ pe aozañ skeudennoù
## Remove button for the various kind of editor.
@ -289,9 +292,16 @@ pdfjs-editor-ink-opacity-input = Boullder
pdfjs-editor-stamp-add-image-button =
.title = Ouzhpennañ ur skeudenn
pdfjs-editor-stamp-add-image-button-label = Ouzhpennañ ur skeudenn
pdfjs-free-text =
.aria-label = Aozer testennoù
pdfjs-ink =
.aria-label = Aozer tresoù
pdfjs-ink-canvas =
.aria-label = Skeudenn bet krouet gant an implijer·ez
## Alt-text dialog
pdfjs-editor-alt-text-add-description-label = Ouzhpennañ un deskrivadur
pdfjs-editor-alt-text-cancel-button = Nullañ
pdfjs-editor-alt-text-save-button = Enrollañ

View File

@ -301,8 +301,6 @@ pdfjs-editor-ink-button-label = Dibujar
pdfjs-editor-stamp-button =
.title = Añadir o editar imágenes
pdfjs-editor-stamp-button-label = Añadir o editar imágenes
pdfjs-editor-remove-button =
.title = Eliminar
pdfjs-editor-highlight-button =
.title = Resaltar
pdfjs-editor-highlight-button-label = Resaltar
@ -329,6 +327,10 @@ pdfjs-editor-ink-opacity-input = Opacidad
pdfjs-editor-stamp-add-image-button =
.title = Añadir imagen
pdfjs-editor-stamp-add-image-button-label = Añadir imagen
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Grosor
pdfjs-editor-free-highlight-thickness-title =
.title = Cambiar el grosor al resaltar elementos que no sean texto
pdfjs-free-text =
.aria-label = Editor de texto
pdfjs-free-text-default-content = Empezar a escribir…

View File

@ -301,8 +301,6 @@ pdfjs-editor-ink-button-label = Marrazkia
pdfjs-editor-stamp-button =
.title = Gehitu edo editatu irudiak
pdfjs-editor-stamp-button-label = Gehitu edo editatu irudiak
pdfjs-editor-remove-button =
.title = Kendu
pdfjs-editor-highlight-button =
.title = Nabarmendu
pdfjs-editor-highlight-button-label = Nabarmendu
@ -329,6 +327,10 @@ pdfjs-editor-ink-opacity-input = Opakutasuna
pdfjs-editor-stamp-add-image-button =
.title = Gehitu irudia
pdfjs-editor-stamp-add-image-button-label = Gehitu irudia
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Loditasuna
pdfjs-editor-free-highlight-thickness-title =
.title = Aldatu loditasuna testua ez beste elementuak nabarmentzean
pdfjs-free-text =
.aria-label = Testu-editorea
pdfjs-free-text-default-content = Hasi idazten…

View File

@ -301,6 +301,18 @@ pdfjs-editor-ink-button-label = Debuxo
pdfjs-editor-stamp-button =
.title = Engadir ou editar imaxes
pdfjs-editor-stamp-button-label = Engadir ou editar imaxes
## Remove button for the various kind of editor.
pdfjs-editor-remove-freetext-button =
.title = Eliminar o texto
pdfjs-editor-remove-stamp-button =
.title = Eliminar a imaxe
pdfjs-editor-remove-highlight-button =
.title = Eliminar o resaltado
##
# Editor Parameters
pdfjs-editor-free-text-color-input = Cor
pdfjs-editor-free-text-size-input = Tamaño
@ -310,6 +322,8 @@ pdfjs-editor-ink-opacity-input = Opacidade
pdfjs-editor-stamp-add-image-button =
.title = Engadir imaxe
pdfjs-editor-stamp-add-image-button-label = Engadir imaxe
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Grosor
pdfjs-free-text =
.aria-label = Editor de texto
pdfjs-free-text-default-content = Comezar a teclear…
@ -345,3 +359,6 @@ pdfjs-editor-resizer-label-bottom-right = Esquina inferior dereita: cambia o tam
pdfjs-editor-resizer-label-bottom-middle = Abaixo medio: cambia o tamaño
pdfjs-editor-resizer-label-bottom-left = Esquina inferior esquerda: cambia o tamaño
pdfjs-editor-resizer-label-middle-left = Medio esquerdo: cambia o tamaño
## Color picker

View File

@ -321,8 +321,6 @@ pdfjs-editor-remove-highlight-button =
##
pdfjs-editor-remove-button =
.title = Rimuovi
# Editor Parameters
pdfjs-editor-free-text-color-input = Colore
pdfjs-editor-free-text-size-input = Dimensione

View File

@ -301,6 +301,9 @@ pdfjs-editor-ink-button-label = Tegn
pdfjs-editor-stamp-button =
.title = Legg til eller rediger bilder
pdfjs-editor-stamp-button-label = Legg til eller rediger bilder
pdfjs-editor-highlight-button =
.title = Markere
pdfjs-editor-highlight-button-label = Markere
## Remove button for the various kind of editor.
@ -326,6 +329,8 @@ pdfjs-editor-stamp-add-image-button =
pdfjs-editor-stamp-add-image-button-label = Legg til bilde
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Tykkelse
pdfjs-editor-free-highlight-thickness-title =
.title = Endre tykkelse når du markerer andre elementer enn tekst
pdfjs-free-text =
.aria-label = Tekstredigering
pdfjs-free-text-default-content = Begynn å skrive…

View File

@ -301,6 +301,23 @@ pdfjs-editor-ink-button-label = Desenhar
pdfjs-editor-stamp-button =
.title = Adicionar ou editar imagens
pdfjs-editor-stamp-button-label = Adicionar ou editar imagens
pdfjs-editor-highlight-button =
.title = Destaque
pdfjs-editor-highlight-button-label = Destaque
## Remove button for the various kind of editor.
pdfjs-editor-remove-ink-button =
.title = Remover desenho
pdfjs-editor-remove-freetext-button =
.title = Remover texto
pdfjs-editor-remove-stamp-button =
.title = Remover imagem
pdfjs-editor-remove-highlight-button =
.title = Remover destaque
##
# Editor Parameters
pdfjs-editor-free-text-color-input = Cor
pdfjs-editor-free-text-size-input = Tamanho
@ -310,6 +327,10 @@ pdfjs-editor-ink-opacity-input = Opacidade
pdfjs-editor-stamp-add-image-button =
.title = Adicionar imagem
pdfjs-editor-stamp-add-image-button-label = Adicionar imagem
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Espessura
pdfjs-editor-free-highlight-thickness-title =
.title = Alterar espessura quando destacar itens que não sejam texto
pdfjs-free-text =
.aria-label = Editor de texto
pdfjs-free-text-default-content = Começar a digitar…
@ -347,3 +368,22 @@ pdfjs-editor-resizer-label-bottom-right = Canto inferior direito — redimension
pdfjs-editor-resizer-label-bottom-middle = Inferior ao centro — redimensionar
pdfjs-editor-resizer-label-bottom-left = Canto inferior esquerdo — redimensionar
pdfjs-editor-resizer-label-middle-left = Centro à esquerda — redimensionar
## Color picker
# This means "Color used to highlight text"
pdfjs-editor-highlight-colorpicker-label = Cor de destaque
pdfjs-editor-colorpicker-button =
.title = Alterar cor
pdfjs-editor-colorpicker-dropdown =
.aria-label = Escolhas de cor
pdfjs-editor-colorpicker-yellow =
.title = Amarelo
pdfjs-editor-colorpicker-green =
.title = Verde
pdfjs-editor-colorpicker-blue =
.title = Azul
pdfjs-editor-colorpicker-pink =
.title = Rosa
pdfjs-editor-colorpicker-red =
.title = Vermelho

View File

@ -305,8 +305,6 @@ pdfjs-editor-ink-button-label = Riši
pdfjs-editor-stamp-button =
.title = Dodajanje ali urejanje slik
pdfjs-editor-stamp-button-label = Dodajanje ali urejanje slik
pdfjs-editor-remove-button =
.title = Odstrani
pdfjs-editor-highlight-button =
.title = Poudarek
pdfjs-editor-highlight-button-label = Poudarek
@ -333,6 +331,10 @@ pdfjs-editor-ink-opacity-input = Neprosojnost
pdfjs-editor-stamp-add-image-button =
.title = Dodaj sliko
pdfjs-editor-stamp-add-image-button-label = Dodaj sliko
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = Debelina
pdfjs-editor-free-highlight-thickness-title =
.title = Spremeni debelino pri označevanju nebesedilnih elementov
pdfjs-free-text =
.aria-label = Urejevalnik besedila
pdfjs-free-text-default-content = Začnite tipkati …

View File

@ -319,6 +319,10 @@ pdfjs-editor-ink-opacity-input = ความทึบ
pdfjs-editor-stamp-add-image-button =
.title = เพิ่มภาพ
pdfjs-editor-stamp-add-image-button-label = เพิ่มภาพ
# This refers to the thickness of the line used for free highlighting (not bound to text)
pdfjs-editor-free-highlight-thickness-input = ความหนา
pdfjs-editor-free-highlight-thickness-title =
.title = เปลี่ยนความหนาเมื่อเน้นรายการอื่นๆ ที่ไม่ใช่ข้อความ
pdfjs-free-text =
.aria-label = ตัวแก้ไขข้อความ
pdfjs-free-text-default-content = เริ่มพิมพ์…

View File

@ -288,7 +288,7 @@ pdfjs-text-annotation-type =
pdfjs-password-label = Введіть пароль для відкриття цього PDF-файла.
pdfjs-password-invalid = Невірний пароль. Спробуйте ще.
pdfjs-password-ok-button = Гаразд
pdfjs-password-ok-button = OK
pdfjs-password-cancel-button = Скасувати
pdfjs-web-fonts-disabled = Веб-шрифти вимкнено: неможливо використати вбудовані у PDF шрифти.