Add Persian translations and Arabic-script font support
This commit is contained in:
parent
d44861d711
commit
051461fa31
10 changed files with 2465 additions and 5 deletions
BIN
client/assets/localization/Arabic.woff2
Normal file
BIN
client/assets/localization/Arabic.woff2
Normal file
Binary file not shown.
155
client/assets/localization/LICENSE-Noto-Arabic.txt
Normal file
155
client/assets/localization/LICENSE-Noto-Arabic.txt
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: Noto
|
||||
Upstream-Contact: https://github.com/googlei18n/noto-fonts/issues
|
||||
http://groups.google.com/group/noto-font
|
||||
Source: https://github.com/googlei18n/noto-fonts
|
||||
|
||||
Files: *
|
||||
Copyright:
|
||||
2010,2012-2020, Google Inc.
|
||||
2015-2020, Google LLC.
|
||||
License-Grant:
|
||||
This Font Software is licensed under the SIL Open Font License,
|
||||
Version 1.1.
|
||||
License: OFL-1.1
|
||||
|
||||
Files:
|
||||
debian/*
|
||||
Copyright:
|
||||
2013-2020, Jonas Smedegaard <dr@jones.dk>
|
||||
2020, Purism, SPC
|
||||
2013, Vasudev Kamath <kamathvasudev@gmail.com>
|
||||
License-Grant:
|
||||
This program is free software;
|
||||
you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation;
|
||||
either version 3, or (at your option) any later version.
|
||||
License: GPL-3+
|
||||
|
||||
Files:
|
||||
debian/NotoMono/NotoMono-Regular.ttf
|
||||
Copyright:
|
||||
2007, Google Inc.
|
||||
License-Grant:
|
||||
This Font Software is licensed under the SIL Open Font License,
|
||||
Version 1.1.
|
||||
License: OFL-1.1
|
||||
|
||||
License: OFL-1.1
|
||||
PREAMBLE
|
||||
.
|
||||
The goals of the Open Font License (OFL) are to stimulate
|
||||
worldwide development of collaborative font projects,
|
||||
to support the font creation efforts
|
||||
of academic and linguistic communities,
|
||||
and to provide a free and open framework
|
||||
in which fonts may be shared and improved
|
||||
in partnership with others.
|
||||
.
|
||||
The OFL allows the licensed fonts to be used, studied,
|
||||
modified and redistributed freely
|
||||
as long as they are not sold by themselves.
|
||||
The fonts, including any derivative works,
|
||||
can be bundled, embedded,
|
||||
redistributed and/or sold with any software
|
||||
provided that any reserved names are not used
|
||||
by derivative works.
|
||||
The fonts and derivatives, however,
|
||||
cannot be released under any other type of license.
|
||||
The requirement for fonts to remain under this license
|
||||
does not apply to any document
|
||||
created using the fonts or their derivatives.
|
||||
.
|
||||
DEFINITIONS
|
||||
.
|
||||
"Font Software" refers to the set of files
|
||||
released by the Copyright Holder(s) under this license
|
||||
and clearly marked as such.
|
||||
This may include source files, build scripts and documentation.
|
||||
.
|
||||
"Reserved Font Name" refers to any names specified as such
|
||||
after the copyright statement(s).
|
||||
.
|
||||
"Original Version" refers to the collection
|
||||
of Font Software components
|
||||
as distributed by the Copyright Holder(s).
|
||||
.
|
||||
"Modified Version" refers to any derivative
|
||||
made by adding to, deleting, or substituting --
|
||||
in part or in whole --
|
||||
any of the components of the Original Version,
|
||||
by changing formats
|
||||
or by porting the Font Software to a new environment.
|
||||
.
|
||||
"Author" refers to any designer, engineer, programmer,
|
||||
technical writer or other person
|
||||
who contributed to the Font Software.
|
||||
.
|
||||
PERMISSION & CONDITIONS
|
||||
.
|
||||
Permission is hereby granted, free of charge,
|
||||
to any person obtaining a copy of the Font Software,
|
||||
to use, study, copy, merge, embed, modify, redistribute,
|
||||
and sell modified and unmodified copies of the Font Software,
|
||||
subject to the following conditions:
|
||||
.
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions,
|
||||
may be sold by itself.
|
||||
.
|
||||
2) Original or Modified Versions of the Font Software
|
||||
may be bundled, redistributed and/or sold with any software,
|
||||
provided that each copy contains the above copyright notice
|
||||
and this license.
|
||||
These can be included either as stand-alone text files,
|
||||
human-readable headers or in the appropriate
|
||||
machine-readable metadata fields within text or binary files
|
||||
as long as those fields can be easily viewed by the user.
|
||||
.
|
||||
3) No Modified Version of the Font Software may use
|
||||
the Reserved Font Name(s)
|
||||
unless explicit written permission is granted
|
||||
by the corresponding Copyright Holder.
|
||||
This restriction only applies to the primary font name
|
||||
as presented to the users.
|
||||
.
|
||||
4) The name(s) of the Copyright Holder(s)
|
||||
or the Author(s) of the Font Software
|
||||
shall not be used to promote,
|
||||
endorse or advertise any Modified Version,
|
||||
except to acknowledge the contribution(s)
|
||||
of the Copyright Holder(s) and the Author(s)
|
||||
or with their explicit written permission.
|
||||
.
|
||||
5) The Font Software,
|
||||
modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license,
|
||||
and must not be distributed under any other license.
|
||||
The requirement for fonts to remain under this license
|
||||
does not apply to any document
|
||||
created using the Font Software.
|
||||
.
|
||||
TERMINATION
|
||||
.
|
||||
This license becomes null and void
|
||||
if any of the above conditions are not met.
|
||||
.
|
||||
DISCLAIMER
|
||||
.
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS",
|
||||
WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO
|
||||
ANY WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE
|
||||
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT,
|
||||
INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF THE USE OR INABILITY TO USE
|
||||
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
License: GPL-3+
|
||||
License-Reference: /usr/share/common-licenses/GPL-3
|
||||
|
|
@ -4,10 +4,14 @@ The BGS client reads the shared `preferences.locale` value. JSON catalogues in `
|
|||
|
||||
English keeps the original macroquad text renderer. Other languages use browser-shaped text cached as WebGL textures, so Devanagari shaping and Korean/Chinese glyphs work correctly. Text measurement and wrapping use the same font and translated text as drawing. Chat/state/actions are never translated or modified. Player names are excluded. Native desktop clients continue to use English.
|
||||
|
||||
`client/assets/localization` includes subsets of Noto Sans Devanagari and Noto Sans CJK, licensed under the SIL Open Font License; notices are included alongside the fonts. Regenerate the subsets after adding translation characters, using fontTools and the corresponding Noto source fonts. The Latin/Greek/Cyrillic renderer uses the existing Source Sans 3 asset.
|
||||
`client/assets/localization` includes subsets of Noto Sans Arabic, Noto Sans Devanagari and Noto Sans CJK, licensed under the SIL Open Font License; notices are included alongside the fonts. Regenerate the subsets after adding translation characters, using fontTools and the corresponding Noto source fonts. The Latin/Greek/Cyrillic renderer uses the existing Source Sans 3 asset.
|
||||
|
||||
For a BGS release, build the client against the engine version currently deployed. Keep the JS, WASM, fonts and other assets in the same immutable release directory. The browser smoke test should exercise the deployed engine's state format and at least one Latin, Devanagari, Korean and Traditional Chinese locale. Publishing this viewer must not change the engine package or game visibility.
|
||||
|
||||
When hosting assets on another origin, allow cross-origin GET and HEAD requests from BGS. The WASM fetch and browser font loading require CORS response headers; a successful asset download alone does not verify that the viewer can load it. Test from the BGS origin before switching the published viewer URL.
|
||||
|
||||
With fontTools' WOFF support and the Noto source fonts installed, run `python scripts/build-localization-fonts.py` from the repository root. Font paths can be supplied with `--cjk-font` and `--devanagari-font`. Keep the OFL notices when redistributing regenerated fonts.
|
||||
With fontTools' WOFF support and the Noto source fonts installed, run `python scripts/build-localization-fonts.py` from the repository root. Font paths can be supplied with `--cjk-font`, `--devanagari-font` and `--arabic-font`. Keep the OFL notices when redistributing regenerated fonts.
|
||||
|
||||
Persian (`fa`, including `fa-IR`) uses a bundled Noto Sans Arabic subset and browser canvas RTL shaping. Text remains anchored in the existing LTR board coordinates. Regenerate the Arabic font with `scripts/build-localization-fonts.py`.
|
||||
|
||||
The Arabic subset is generated from Debian’s `fonts-noto-core` NotoSansArabic-Regular.ttf. Its upstream provenance and SIL OFL 1.1 copyright/license notice are preserved in `client/assets/localization/LICENSE-Noto-Arabic.txt`.
|
||||
|
|
|
|||
2285
client/js/src/localization/fa.json
Normal file
2285
client/js/src/localization/fa.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -13,6 +13,7 @@ import catalog11 from "./zh-TW.json";
|
|||
import catalog12 from "./vi.json";
|
||||
import catalog13 from "./it.json";
|
||||
import catalog14 from "./nl.json";
|
||||
import catalog15 from "./fa.json";
|
||||
export const catalogs = {
|
||||
en: catalog0,
|
||||
de: catalog1,
|
||||
|
|
@ -29,4 +30,5 @@ export const catalogs = {
|
|||
vi: catalog12,
|
||||
it: catalog13,
|
||||
nl: catalog14,
|
||||
fa: catalog15,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export const languages = {
|
|||
vi: "Tiếng Việt",
|
||||
it: "Italiano",
|
||||
nl: "Nederlands",
|
||||
fa: "فارسی",
|
||||
};
|
||||
|
||||
export function resolveLocale(value) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ export async function setLocale(value, assets) {
|
|||
const requested = ++pendingLocale;
|
||||
const next = resolveLocale(value);
|
||||
const font =
|
||||
next === "hi"
|
||||
next === "fa"
|
||||
? "Arabic"
|
||||
: next === "hi"
|
||||
? "Devanagari"
|
||||
: next === "ko"
|
||||
? "Korean"
|
||||
|
|
@ -67,6 +69,8 @@ function metrics(text, size) {
|
|||
const key = `${size}:${translated}`;
|
||||
if (measurements.has(key)) return measurements.get(key);
|
||||
context.font = `${size}px ${family}`;
|
||||
context.direction = locale === "fa" ? "rtl" : "ltr";
|
||||
context.textAlign = "left";
|
||||
const measured = context.measureText(translated);
|
||||
const left = Math.ceil(Math.max(0, measured.actualBoundingBoxLeft)) + 2;
|
||||
const ascent = Math.ceil(measured.actualBoundingBoxAscent) + 2;
|
||||
|
|
@ -116,6 +120,8 @@ window.bgsTextPixels = (text, size) => {
|
|||
canvas.height = m.height * 2;
|
||||
context.scale(2, 2);
|
||||
context.font = `${size}px ${family}`;
|
||||
context.direction = locale === "fa" ? "rtl" : "ltr";
|
||||
context.textAlign = "left";
|
||||
context.fillStyle = "white";
|
||||
context.fillText(m.translated, m.left, m.ascent);
|
||||
return context.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||
|
|
|
|||
|
|
@ -8,14 +8,15 @@ from fontTools.ttLib import TTFont
|
|||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--cjk-font', default='/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc')
|
||||
parser.add_argument('--devanagari-font', default='/usr/share/fonts/truetype/noto/NotoSansDevanagari-Regular.ttf')
|
||||
parser.add_argument('--arabic-font', default='/usr/share/fonts/truetype/noto/NotoSansArabic-Regular.ttf')
|
||||
args = parser.parse_args()
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
output = root / 'client/assets/localization'
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
for locale, name, index in [('ko', 'Korean', 1), ('zh-TW', 'Chinese', 3), ('hi', 'Devanagari', None)]:
|
||||
for locale, name, index in [('ko', 'Korean', 1), ('zh-TW', 'Chinese', 3), ('hi', 'Devanagari', None), ('fa', 'Arabic', None)]:
|
||||
catalog = json.loads((root / f'client/js/src/localization/{locale}.json').read_text())
|
||||
text = ''.join(catalog.values()) + ''.join(chr(i) for i in range(32, 256))
|
||||
font = TTFont(args.cjk_font, fontNumber=index) if index is not None else TTFont(args.devanagari_font)
|
||||
font = TTFont(args.cjk_font, fontNumber=index) if index is not None else TTFont(args.arabic_font if locale == "fa" else args.devanagari_font)
|
||||
processor = subset.Subsetter(options=subset.Options())
|
||||
processor.populate(text=text)
|
||||
processor.subset(font)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ const locales = [
|
|||
"vi",
|
||||
"it",
|
||||
"nl",
|
||||
"fa",
|
||||
];
|
||||
for (const locale of locales) {
|
||||
const catalog = JSON.parse(
|
||||
|
|
|
|||
|
|
@ -81,3 +81,8 @@ test("game context distinguishes quantities from directions and conscription fro
|
|||
assert.equal(createTranslator(actual, "de").translate("Used Draft"), "Wehrpflicht genutzt");
|
||||
assert.equal(createTranslator(actual, "zh-TW").translate("Used Draft"), "已使用徵兵");
|
||||
});
|
||||
|
||||
test("Persian regional tags select Farsi", () => {
|
||||
assert.equal(resolveLocale("fa-IR"), "fa");
|
||||
assert.equal(resolveLocale("fa_IR"), "fa");
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue