feat(client): localize the BGS viewer in 15 languages
This commit is contained in:
parent
40c75a4377
commit
0d2b85f2e2
35 changed files with 35655 additions and 100 deletions
BIN
client/assets/localization/Chinese.woff2
Normal file
BIN
client/assets/localization/Chinese.woff2
Normal file
Binary file not shown.
BIN
client/assets/localization/Devanagari.woff2
Normal file
BIN
client/assets/localization/Devanagari.woff2
Normal file
Binary file not shown.
BIN
client/assets/localization/Korean.woff2
Normal file
BIN
client/assets/localization/Korean.woff2
Normal file
Binary file not shown.
483
client/assets/localization/LICENSE-Noto.txt
Normal file
483
client/assets/localization/LICENSE-Noto.txt
Normal file
|
|
@ -0,0 +1,483 @@
|
|||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: noto-cjk
|
||||
Upstream-Contact: https://github.com/notofonts/noto-cjk/issues
|
||||
Source: https://github.com/notofonts/noto-cjk
|
||||
Files-Excluded:
|
||||
.gitattributes
|
||||
.gitignore
|
||||
Sans/Mono/NotoSansMonoCJKhk-Bold.otf
|
||||
Sans/Mono/NotoSansMonoCJKhk-Regular.otf
|
||||
Sans/Mono/NotoSansMonoCJKjp-Bold.otf
|
||||
Sans/Mono/NotoSansMonoCJKjp-Regular.otf
|
||||
Sans/Mono/NotoSansMonoCJKkr-Bold.otf
|
||||
Sans/Mono/NotoSansMonoCJKkr-Regular.otf
|
||||
Sans/Mono/NotoSansMonoCJKsc-Bold.otf
|
||||
Sans/Mono/NotoSansMonoCJKsc-Regular.otf
|
||||
Sans/Mono/NotoSansMonoCJKtc-Bold.otf
|
||||
Sans/Mono/NotoSansMonoCJKtc-Regular.otf
|
||||
Sans/OTF/Japanese/NotoSansCJKjp-Black.otf
|
||||
Sans/OTF/Japanese/NotoSansCJKjp-Bold.otf
|
||||
Sans/OTF/Japanese/NotoSansCJKjp-DemiLight.otf
|
||||
Sans/OTF/Japanese/NotoSansCJKjp-Light.otf
|
||||
Sans/OTF/Japanese/NotoSansCJKjp-Medium.otf
|
||||
Sans/OTF/Japanese/NotoSansCJKjp-Regular.otf
|
||||
Sans/OTF/Japanese/NotoSansCJKjp-Thin.otf
|
||||
Sans/OTF/Korean/NotoSansCJKkr-Black.otf
|
||||
Sans/OTF/Korean/NotoSansCJKkr-Bold.otf
|
||||
Sans/OTF/Korean/NotoSansCJKkr-DemiLight.otf
|
||||
Sans/OTF/Korean/NotoSansCJKkr-Light.otf
|
||||
Sans/OTF/Korean/NotoSansCJKkr-Medium.otf
|
||||
Sans/OTF/Korean/NotoSansCJKkr-Regular.otf
|
||||
Sans/OTF/Korean/NotoSansCJKkr-Thin.otf
|
||||
Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Black.otf
|
||||
Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Bold.otf
|
||||
Sans/OTF/SimplifiedChinese/NotoSansCJKsc-DemiLight.otf
|
||||
Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Light.otf
|
||||
Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Medium.otf
|
||||
Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Regular.otf
|
||||
Sans/OTF/SimplifiedChinese/NotoSansCJKsc-Thin.otf
|
||||
Sans/OTF/TraditionalChinese/NotoSansCJKtc-Black.otf
|
||||
Sans/OTF/TraditionalChinese/NotoSansCJKtc-Bold.otf
|
||||
Sans/OTF/TraditionalChinese/NotoSansCJKtc-DemiLight.otf
|
||||
Sans/OTF/TraditionalChinese/NotoSansCJKtc-Light.otf
|
||||
Sans/OTF/TraditionalChinese/NotoSansCJKtc-Medium.otf
|
||||
Sans/OTF/TraditionalChinese/NotoSansCJKtc-Regular.otf
|
||||
Sans/OTF/TraditionalChinese/NotoSansCJKtc-Thin.otf
|
||||
Sans/OTF/TraditionalChineseHK/NotoSansCJKhk-Black.otf
|
||||
Sans/OTF/TraditionalChineseHK/NotoSansCJKhk-Bold.otf
|
||||
Sans/OTF/TraditionalChineseHK/NotoSansCJKhk-DemiLight.otf
|
||||
Sans/OTF/TraditionalChineseHK/NotoSansCJKhk-Light.otf
|
||||
Sans/OTF/TraditionalChineseHK/NotoSansCJKhk-Medium.otf
|
||||
Sans/OTF/TraditionalChineseHK/NotoSansCJKhk-Regular.otf
|
||||
Sans/OTF/TraditionalChineseHK/NotoSansCJKhk-Thin.otf
|
||||
Sans/SubsetOTF/HK/NotoSansHK-Black.otf
|
||||
Sans/SubsetOTF/HK/NotoSansHK-Bold.otf
|
||||
Sans/SubsetOTF/HK/NotoSansHK-DemiLight.otf
|
||||
Sans/SubsetOTF/HK/NotoSansHK-Light.otf
|
||||
Sans/SubsetOTF/HK/NotoSansHK-Medium.otf
|
||||
Sans/SubsetOTF/HK/NotoSansHK-Regular.otf
|
||||
Sans/SubsetOTF/HK/NotoSansHK-Thin.otf
|
||||
Sans/SubsetOTF/JP/NotoSansJP-Black.otf
|
||||
Sans/SubsetOTF/JP/NotoSansJP-Bold.otf
|
||||
Sans/SubsetOTF/JP/NotoSansJP-DemiLight.otf
|
||||
Sans/SubsetOTF/JP/NotoSansJP-Light.otf
|
||||
Sans/SubsetOTF/JP/NotoSansJP-Medium.otf
|
||||
Sans/SubsetOTF/JP/NotoSansJP-Regular.otf
|
||||
Sans/SubsetOTF/JP/NotoSansJP-Thin.otf
|
||||
Sans/SubsetOTF/KR/NotoSansKR-Black.otf
|
||||
Sans/SubsetOTF/KR/NotoSansKR-Bold.otf
|
||||
Sans/SubsetOTF/KR/NotoSansKR-DemiLight.otf
|
||||
Sans/SubsetOTF/KR/NotoSansKR-Light.otf
|
||||
Sans/SubsetOTF/KR/NotoSansKR-Medium.otf
|
||||
Sans/SubsetOTF/KR/NotoSansKR-Regular.otf
|
||||
Sans/SubsetOTF/KR/NotoSansKR-Thin.otf
|
||||
Sans/SubsetOTF/SC/NotoSansSC-Black.otf
|
||||
Sans/SubsetOTF/SC/NotoSansSC-Bold.otf
|
||||
Sans/SubsetOTF/SC/NotoSansSC-DemiLight.otf
|
||||
Sans/SubsetOTF/SC/NotoSansSC-Light.otf
|
||||
Sans/SubsetOTF/SC/NotoSansSC-Medium.otf
|
||||
Sans/SubsetOTF/SC/NotoSansSC-Regular.otf
|
||||
Sans/SubsetOTF/SC/NotoSansSC-Thin.otf
|
||||
Sans/SubsetOTF/TC/NotoSansTC-Black.otf
|
||||
Sans/SubsetOTF/TC/NotoSansTC-Bold.otf
|
||||
Sans/SubsetOTF/TC/NotoSansTC-DemiLight.otf
|
||||
Sans/SubsetOTF/TC/NotoSansTC-Light.otf
|
||||
Sans/SubsetOTF/TC/NotoSansTC-Medium.otf
|
||||
Sans/SubsetOTF/TC/NotoSansTC-Regular.otf
|
||||
Sans/SubsetOTF/TC/NotoSansTC-Thin.otf
|
||||
Sans/SuperOTC/NotoSansCJK.ttc.zip
|
||||
Sans/Variable/OTC/NotoSansCJK-VF.ttf.ttc
|
||||
Sans/Variable/OTC/NotoSansMonoCJK-VF.ttf.ttc
|
||||
Sans/Variable/OTF/Mono/NotoSansMonoCJKhk-VF.otf
|
||||
Sans/Variable/OTF/Mono/NotoSansMonoCJKjp-VF.otf
|
||||
Sans/Variable/OTF/Mono/NotoSansMonoCJKkr-VF.otf
|
||||
Sans/Variable/OTF/Mono/NotoSansMonoCJKsc-VF.otf
|
||||
Sans/Variable/OTF/Mono/NotoSansMonoCJKtc-VF.otf
|
||||
Sans/Variable/OTF/NotoSansCJKhk-VF.otf
|
||||
Sans/Variable/OTF/NotoSansCJKjp-VF.otf
|
||||
Sans/Variable/OTF/NotoSansCJKkr-VF.otf
|
||||
Sans/Variable/OTF/NotoSansCJKsc-VF.otf
|
||||
Sans/Variable/OTF/NotoSansCJKtc-VF.otf
|
||||
Sans/Variable/OTF/Subset/NotoSansHK-VF.otf
|
||||
Sans/Variable/OTF/Subset/NotoSansJP-VF.otf
|
||||
Sans/Variable/OTF/Subset/NotoSansKR-VF.otf
|
||||
Sans/Variable/OTF/Subset/NotoSansSC-VF.otf
|
||||
Sans/Variable/OTF/Subset/NotoSansTC-VF.otf
|
||||
Sans/Variable/TTF/Mono/NotoSansMonoCJKhk-VF.ttf
|
||||
Sans/Variable/TTF/Mono/NotoSansMonoCJKjp-VF.ttf
|
||||
Sans/Variable/TTF/Mono/NotoSansMonoCJKkr-VF.ttf
|
||||
Sans/Variable/TTF/Mono/NotoSansMonoCJKsc-VF.ttf
|
||||
Sans/Variable/TTF/Mono/NotoSansMonoCJKtc-VF.ttf
|
||||
Sans/Variable/TTF/NotoSansCJKhk-VF.ttf
|
||||
Sans/Variable/TTF/NotoSansCJKjp-VF.ttf
|
||||
Sans/Variable/TTF/NotoSansCJKkr-VF.ttf
|
||||
Sans/Variable/TTF/NotoSansCJKsc-VF.ttf
|
||||
Sans/Variable/TTF/NotoSansCJKtc-VF.ttf
|
||||
Sans/Variable/TTF/Subset/NotoSansHK-VF.ttf
|
||||
Sans/Variable/TTF/Subset/NotoSansJP-VF.ttf
|
||||
Sans/Variable/TTF/Subset/NotoSansKR-VF.ttf
|
||||
Sans/Variable/TTF/Subset/NotoSansSC-VF.ttf
|
||||
Sans/Variable/TTF/Subset/NotoSansTC-VF.ttf
|
||||
Serif/OTF/Japanese/NotoSerifCJKjp-Black.otf
|
||||
Serif/OTF/Japanese/NotoSerifCJKjp-Bold.otf
|
||||
Serif/OTF/Japanese/NotoSerifCJKjp-ExtraLight.otf
|
||||
Serif/OTF/Japanese/NotoSerifCJKjp-Light.otf
|
||||
Serif/OTF/Japanese/NotoSerifCJKjp-Medium.otf
|
||||
Serif/OTF/Japanese/NotoSerifCJKjp-Regular.otf
|
||||
Serif/OTF/Japanese/NotoSerifCJKjp-SemiBold.otf
|
||||
Serif/OTF/Korean/NotoSerifCJKkr-Black.otf
|
||||
Serif/OTF/Korean/NotoSerifCJKkr-Bold.otf
|
||||
Serif/OTF/Korean/NotoSerifCJKkr-ExtraLight.otf
|
||||
Serif/OTF/Korean/NotoSerifCJKkr-Light.otf
|
||||
Serif/OTF/Korean/NotoSerifCJKkr-Medium.otf
|
||||
Serif/OTF/Korean/NotoSerifCJKkr-Regular.otf
|
||||
Serif/OTF/Korean/NotoSerifCJKkr-SemiBold.otf
|
||||
Serif/OTF/SimplifiedChinese/NotoSerifCJKsc-Black.otf
|
||||
Serif/OTF/SimplifiedChinese/NotoSerifCJKsc-Bold.otf
|
||||
Serif/OTF/SimplifiedChinese/NotoSerifCJKsc-ExtraLight.otf
|
||||
Serif/OTF/SimplifiedChinese/NotoSerifCJKsc-Light.otf
|
||||
Serif/OTF/SimplifiedChinese/NotoSerifCJKsc-Medium.otf
|
||||
Serif/OTF/SimplifiedChinese/NotoSerifCJKsc-Regular.otf
|
||||
Serif/OTF/SimplifiedChinese/NotoSerifCJKsc-SemiBold.otf
|
||||
Serif/OTF/TraditionalChinese/NotoSerifCJKtc-Black.otf
|
||||
Serif/OTF/TraditionalChinese/NotoSerifCJKtc-Bold.otf
|
||||
Serif/OTF/TraditionalChinese/NotoSerifCJKtc-ExtraLight.otf
|
||||
Serif/OTF/TraditionalChinese/NotoSerifCJKtc-Light.otf
|
||||
Serif/OTF/TraditionalChinese/NotoSerifCJKtc-Medium.otf
|
||||
Serif/OTF/TraditionalChinese/NotoSerifCJKtc-Regular.otf
|
||||
Serif/OTF/TraditionalChinese/NotoSerifCJKtc-SemiBold.otf
|
||||
Serif/OTF/TraditionalChineseHK/NotoSerifCJKhk-Black.otf
|
||||
Serif/OTF/TraditionalChineseHK/NotoSerifCJKhk-Bold.otf
|
||||
Serif/OTF/TraditionalChineseHK/NotoSerifCJKhk-ExtraLight.otf
|
||||
Serif/OTF/TraditionalChineseHK/NotoSerifCJKhk-Light.otf
|
||||
Serif/OTF/TraditionalChineseHK/NotoSerifCJKhk-Medium.otf
|
||||
Serif/OTF/TraditionalChineseHK/NotoSerifCJKhk-Regular.otf
|
||||
Serif/OTF/TraditionalChineseHK/NotoSerifCJKhk-SemiBold.otf
|
||||
Serif/SubsetOTF/HK/NotoSerifHK-Black.otf
|
||||
Serif/SubsetOTF/HK/NotoSerifHK-Bold.otf
|
||||
Serif/SubsetOTF/HK/NotoSerifHK-ExtraLight.otf
|
||||
Serif/SubsetOTF/HK/NotoSerifHK-Light.otf
|
||||
Serif/SubsetOTF/HK/NotoSerifHK-Medium.otf
|
||||
Serif/SubsetOTF/HK/NotoSerifHK-Regular.otf
|
||||
Serif/SubsetOTF/HK/NotoSerifHK-SemiBold.otf
|
||||
Serif/SubsetOTF/JP/NotoSerifJP-Black.otf
|
||||
Serif/SubsetOTF/JP/NotoSerifJP-Bold.otf
|
||||
Serif/SubsetOTF/JP/NotoSerifJP-ExtraLight.otf
|
||||
Serif/SubsetOTF/JP/NotoSerifJP-Light.otf
|
||||
Serif/SubsetOTF/JP/NotoSerifJP-Medium.otf
|
||||
Serif/SubsetOTF/JP/NotoSerifJP-Regular.otf
|
||||
Serif/SubsetOTF/JP/NotoSerifJP-SemiBold.otf
|
||||
Serif/SubsetOTF/KR/NotoSerifKR-Black.otf
|
||||
Serif/SubsetOTF/KR/NotoSerifKR-Bold.otf
|
||||
Serif/SubsetOTF/KR/NotoSerifKR-ExtraLight.otf
|
||||
Serif/SubsetOTF/KR/NotoSerifKR-Light.otf
|
||||
Serif/SubsetOTF/KR/NotoSerifKR-Medium.otf
|
||||
Serif/SubsetOTF/KR/NotoSerifKR-Regular.otf
|
||||
Serif/SubsetOTF/KR/NotoSerifKR-SemiBold.otf
|
||||
Serif/SubsetOTF/SC/NotoSerifSC-Black.otf
|
||||
Serif/SubsetOTF/SC/NotoSerifSC-Bold.otf
|
||||
Serif/SubsetOTF/SC/NotoSerifSC-ExtraLight.otf
|
||||
Serif/SubsetOTF/SC/NotoSerifSC-Light.otf
|
||||
Serif/SubsetOTF/SC/NotoSerifSC-Medium.otf
|
||||
Serif/SubsetOTF/SC/NotoSerifSC-Regular.otf
|
||||
Serif/SubsetOTF/SC/NotoSerifSC-SemiBold.otf
|
||||
Serif/SubsetOTF/TC/NotoSerifTC-Black.otf
|
||||
Serif/SubsetOTF/TC/NotoSerifTC-Bold.otf
|
||||
Serif/SubsetOTF/TC/NotoSerifTC-ExtraLight.otf
|
||||
Serif/SubsetOTF/TC/NotoSerifTC-Light.otf
|
||||
Serif/SubsetOTF/TC/NotoSerifTC-Medium.otf
|
||||
Serif/SubsetOTF/TC/NotoSerifTC-Regular.otf
|
||||
Serif/SubsetOTF/TC/NotoSerifTC-SemiBold.otf
|
||||
Serif/Variable/OTC/NotoSerifCJK-VF.ttf.ttc
|
||||
Serif/Variable/OTF/NotoSerifCJKhk-VF.otf
|
||||
Serif/Variable/OTF/NotoSerifCJKjp-VF.otf
|
||||
Serif/Variable/OTF/NotoSerifCJKkr-VF.otf
|
||||
Serif/Variable/OTF/NotoSerifCJKsc-VF.otf
|
||||
Serif/Variable/OTF/NotoSerifCJKtc-VF.otf
|
||||
Serif/Variable/OTF/Subset/NotoSerifHK-VF.otf
|
||||
Serif/Variable/OTF/Subset/NotoSerifJP-VF.otf
|
||||
Serif/Variable/OTF/Subset/NotoSerifKR-VF.otf
|
||||
Serif/Variable/OTF/Subset/NotoSerifSC-VF.otf
|
||||
Serif/Variable/OTF/Subset/NotoSerifTC-VF.otf
|
||||
Serif/Variable/TTF/NotoSerifCJKhk-VF.ttf
|
||||
Serif/Variable/TTF/NotoSerifCJKjp-VF.ttf
|
||||
Serif/Variable/TTF/NotoSerifCJKkr-VF.ttf
|
||||
Serif/Variable/TTF/NotoSerifCJKsc-VF.ttf
|
||||
Serif/Variable/TTF/NotoSerifCJKtc-VF.ttf
|
||||
Serif/Variable/TTF/Subset/NotoSerifHK-VF.ttf
|
||||
Serif/Variable/TTF/Subset/NotoSerifJP-VF.ttf
|
||||
Serif/Variable/TTF/Subset/NotoSerifKR-VF.ttf
|
||||
Serif/Variable/TTF/Subset/NotoSerifSC-VF.ttf
|
||||
Serif/Variable/TTF/Subset/NotoSerifTC-VF.ttf
|
||||
|
||||
Files: *
|
||||
Copyright: 2010-2012, Google Corporation
|
||||
License: SIL-1.1
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2013, Vasudev Kamath <kamathvasudev@gmail.com>
|
||||
2013-2015, Jonas Smedegaard <dr@jones.dk>
|
||||
2015-2022, ChangZhuo Chen (陳昌倬) <czchen@debian.org>
|
||||
License: GPL-3+
|
||||
|
||||
License: SIL-1.1
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
.
|
||||
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+
|
||||
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 of the License, or
|
||||
(at your option) any later version.
|
||||
.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
.
|
||||
On Debian systems, the complete text of the GNU General
|
||||
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
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
|
||||
|
|
@ -1,72 +1,81 @@
|
|||
import {EventEmitter} from "events";
|
||||
import { setLocale, setPlayers } from "./localized-text";
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
export class Control extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = null;
|
||||
this.player_index = null;
|
||||
this.preferences = "";
|
||||
this._assets_url = null;
|
||||
constructor() {
|
||||
super();
|
||||
this.state = null;
|
||||
this.player_index = null;
|
||||
this.preferences = "";
|
||||
this._assets_url = null;
|
||||
|
||||
this.addListener("state", (data) => {
|
||||
this.state = data;
|
||||
});
|
||||
// When we receive log slices, when executing a move
|
||||
this.addListener("gamelog", (logData) => {
|
||||
// Ignore the log data and tell the backend we want the new state
|
||||
this.emit("fetchState");
|
||||
});
|
||||
this.addListener("state:updated", () => {
|
||||
this.emit("fetchState");
|
||||
});
|
||||
this.addListener("player", (player) => {
|
||||
this.player_index = player.index;
|
||||
});
|
||||
this.addListener("preferences", (preferences) => {
|
||||
this.preferences = JSON.stringify(preferences);
|
||||
});
|
||||
}
|
||||
this.addListener("state", (data) => {
|
||||
setPlayers(data);
|
||||
this.state = data;
|
||||
});
|
||||
// When we receive log slices, when executing a move
|
||||
this.addListener("gamelog", (logData) => {
|
||||
// Ignore the log data and tell the backend we want the new state
|
||||
this.emit("fetchState");
|
||||
});
|
||||
this.addListener("state:updated", () => {
|
||||
this.emit("fetchState");
|
||||
});
|
||||
this.addListener("player", (player) => {
|
||||
this.player_index = player.index;
|
||||
});
|
||||
let preferencesRevision = 0;
|
||||
this.addListener("preferences", async (preferences) => {
|
||||
const requested = ++preferencesRevision;
|
||||
try {
|
||||
await setLocale(
|
||||
preferences.locale,
|
||||
this._assets_url || new URL("assets/", location.href).href,
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn("Could not load game font", error);
|
||||
}
|
||||
if (requested === preferencesRevision)
|
||||
this.preferences = JSON.stringify(preferences);
|
||||
});
|
||||
}
|
||||
|
||||
receive_state() {
|
||||
const state = this.state;
|
||||
this.state = null;
|
||||
return state;
|
||||
}
|
||||
receive_state() {
|
||||
const state = this.state;
|
||||
this.state = null;
|
||||
return state;
|
||||
}
|
||||
|
||||
receive_player_index() {
|
||||
const index = this.player_index;
|
||||
this.player_index = null;
|
||||
return index;
|
||||
}
|
||||
|
||||
receive_preferences() {
|
||||
const prefs = this.preferences;
|
||||
this.preferences = "";
|
||||
return prefs;
|
||||
}
|
||||
receive_player_index() {
|
||||
const index = this.player_index;
|
||||
this.player_index = null;
|
||||
return index;
|
||||
}
|
||||
|
||||
send_move(move) {
|
||||
this.emit("move", move);
|
||||
}
|
||||
receive_preferences() {
|
||||
const prefs = this.preferences;
|
||||
this.preferences = "";
|
||||
return prefs;
|
||||
}
|
||||
|
||||
send_ready() {
|
||||
console.log("Sending ready");
|
||||
this.emit("ready");
|
||||
}
|
||||
send_move(move) {
|
||||
this.emit("move", move);
|
||||
}
|
||||
|
||||
get canvas_size() {
|
||||
return document.getElementById("glcanvas").getBoundingClientRect();
|
||||
}
|
||||
send_ready() {
|
||||
console.log("Sending ready");
|
||||
this.emit("ready");
|
||||
}
|
||||
|
||||
get assets_url() {
|
||||
return this._assets_url;
|
||||
}
|
||||
get canvas_size() {
|
||||
return document.getElementById("glcanvas").getBoundingClientRect();
|
||||
}
|
||||
|
||||
set assets_url(value) {
|
||||
this._assets_url = value;
|
||||
}
|
||||
get assets_url() {
|
||||
return this._assets_url;
|
||||
}
|
||||
|
||||
set assets_url(value) {
|
||||
this._assets_url = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
import {Control} from "./control";
|
||||
import {run} from "./run";
|
||||
import { Control } from "./control";
|
||||
import { run } from "./run";
|
||||
|
||||
const viewerScriptUrl = document.currentScript?.src;
|
||||
window.clash = {
|
||||
launch(selector) {
|
||||
const control = new Control();
|
||||
window.clash_control = control;
|
||||
launch(selector) {
|
||||
const control = new Control();
|
||||
if (viewerScriptUrl)
|
||||
control.assets_url = new URL("assets/", viewerScriptUrl).href;
|
||||
window.clash_control = control;
|
||||
|
||||
run({selector, control});
|
||||
run({ selector, control });
|
||||
|
||||
return control;
|
||||
},
|
||||
return control;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
11
client/js/src/localization/README.md
Normal file
11
client/js/src/localization/README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Browser localization
|
||||
|
||||
The BGS client reads the shared `preferences.locale` value. JSON catalogues in `client/js/src/localization` cover all 15 BGS languages. Keys are source UI strings; placeholders such as `{p0}` must be preserved. Run `node scripts/check-locales.mjs client/js/src/localization` and `node --test scripts/localization.test.mjs` after editing them. Initial translations were machine-assisted and should be reviewed for game terminology.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
2284
client/js/src/localization/da.json
Normal file
2284
client/js/src/localization/da.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/de.json
Normal file
2284
client/js/src/localization/de.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/el.json
Normal file
2284
client/js/src/localization/el.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/en.json
Normal file
2284
client/js/src/localization/en.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/fr.json
Normal file
2284
client/js/src/localization/fr.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/hi.json
Normal file
2284
client/js/src/localization/hi.json
Normal file
File diff suppressed because it is too large
Load diff
1
client/js/src/localization/index.d.ts
vendored
Normal file
1
client/js/src/localization/index.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export const catalogs: Record<string, Record<string, string>>;
|
||||
32
client/js/src/localization/index.js
Normal file
32
client/js/src/localization/index.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import catalog0 from "./en.json";
|
||||
import catalog1 from "./de.json";
|
||||
import catalog2 from "./fr.json";
|
||||
import catalog3 from "./pl.json";
|
||||
import catalog4 from "./ro.json";
|
||||
import catalog5 from "./el.json";
|
||||
import catalog6 from "./hi.json";
|
||||
import catalog7 from "./ru.json";
|
||||
import catalog8 from "./da.json";
|
||||
import catalog9 from "./pt-BR.json";
|
||||
import catalog10 from "./ko.json";
|
||||
import catalog11 from "./zh-TW.json";
|
||||
import catalog12 from "./vi.json";
|
||||
import catalog13 from "./it.json";
|
||||
import catalog14 from "./nl.json";
|
||||
export const catalogs = {
|
||||
en: catalog0,
|
||||
de: catalog1,
|
||||
fr: catalog2,
|
||||
pl: catalog3,
|
||||
ro: catalog4,
|
||||
el: catalog5,
|
||||
hi: catalog6,
|
||||
ru: catalog7,
|
||||
da: catalog8,
|
||||
"pt-BR": catalog9,
|
||||
ko: catalog10,
|
||||
"zh-TW": catalog11,
|
||||
vi: catalog12,
|
||||
it: catalog13,
|
||||
nl: catalog14,
|
||||
};
|
||||
2284
client/js/src/localization/it.json
Normal file
2284
client/js/src/localization/it.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/ko.json
Normal file
2284
client/js/src/localization/ko.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/nl.json
Normal file
2284
client/js/src/localization/nl.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/pl.json
Normal file
2284
client/js/src/localization/pl.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/pt-BR.json
Normal file
2284
client/js/src/localization/pt-BR.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/ro.json
Normal file
2284
client/js/src/localization/ro.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/ru.json
Normal file
2284
client/js/src/localization/ru.json
Normal file
File diff suppressed because it is too large
Load diff
319
client/js/src/localization/runtime.js
Normal file
319
client/js/src/localization/runtime.js
Normal file
|
|
@ -0,0 +1,319 @@
|
|||
export const languages = {
|
||||
en: "English",
|
||||
de: "Deutsch",
|
||||
fr: "Français",
|
||||
pl: "Polski",
|
||||
ro: "Română",
|
||||
el: "Ελληνικά",
|
||||
hi: "हिन्दी",
|
||||
ru: "Русский",
|
||||
da: "Dansk",
|
||||
"pt-BR": "Português (Brasil)",
|
||||
ko: "한국어",
|
||||
"zh-TW": "繁體中文",
|
||||
vi: "Tiếng Việt",
|
||||
it: "Italiano",
|
||||
nl: "Nederlands",
|
||||
};
|
||||
|
||||
export function resolveLocale(value) {
|
||||
if (typeof value !== "string") {
|
||||
return "en";
|
||||
}
|
||||
const tag = value.toLowerCase().replaceAll("_", "-");
|
||||
const exact = Object.keys(languages).find(
|
||||
(locale) => locale.toLowerCase() === tag,
|
||||
);
|
||||
if (exact) {
|
||||
return exact;
|
||||
}
|
||||
if (tag === "pt" || tag.startsWith("pt-")) {
|
||||
return "pt-BR";
|
||||
}
|
||||
if (/^zh-(?:tw|hk|mo|hant)(?:-|$)/.test(tag)) {
|
||||
return "zh-TW";
|
||||
}
|
||||
return (
|
||||
Object.keys(languages).find((locale) => locale === tag.split("-")[0]) ??
|
||||
"en"
|
||||
);
|
||||
}
|
||||
|
||||
const normalize = (text) => text.replace(/\s+/g, " ").trim();
|
||||
|
||||
export function createTranslator(catalogs, initialLocale = "en") {
|
||||
let locale = resolveLocale(initialLocale);
|
||||
let names = new Set();
|
||||
let patterns = [];
|
||||
let upperCase = new Map();
|
||||
const cache = new Map();
|
||||
function prepare() {
|
||||
cache.clear();
|
||||
upperCase = new Map(
|
||||
Object.entries(catalogs[locale] ?? {})
|
||||
.filter(([source]) => !/\{p\d+\}/.test(source))
|
||||
.map(([source, value]) => [
|
||||
source.toLocaleUpperCase(),
|
||||
value.toLocaleUpperCase(),
|
||||
]),
|
||||
);
|
||||
patterns = Object.keys(catalogs[locale] ?? {})
|
||||
.filter(
|
||||
(source) =>
|
||||
/\{p\d+\}/.test(source) &&
|
||||
source.replace(/\{p\d+\}/g, "").trim().length >= 1,
|
||||
)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
b.replace(/\{p\d+\}/g, "").length - a.replace(/\{p\d+\}/g, "").length,
|
||||
)
|
||||
.map((source) => ({ source, pieces: source.split(/(\{p\d+\})/) }))
|
||||
.filter(({ pieces }) =>
|
||||
pieces.every(
|
||||
(piece, i) =>
|
||||
i === 0 ||
|
||||
i === pieces.length - 1 ||
|
||||
i % 2 !== 0 ||
|
||||
piece.length > 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
function translate(value, depth = 0) {
|
||||
if (typeof value !== "string" || locale === "en") {
|
||||
return value;
|
||||
}
|
||||
const text = normalize(value);
|
||||
if (!text || names.has(text) || !/[A-Za-zÀ-ž]/.test(text)) {
|
||||
return value;
|
||||
}
|
||||
const catalog = catalogs[locale] ?? {};
|
||||
let translated = Object.prototype.hasOwnProperty.call(catalog, text)
|
||||
? catalog[text]
|
||||
: undefined;
|
||||
if (translated === undefined && text === text.toLocaleUpperCase()) {
|
||||
translated = upperCase.get(text);
|
||||
}
|
||||
if (translated === undefined && cache.has(text)) {
|
||||
translated = cache.get(text);
|
||||
}
|
||||
if (translated === undefined && depth < 2 && text.length <= 2500) {
|
||||
for (const { source, pieces } of patterns) {
|
||||
if (!text.startsWith(pieces[0])) {
|
||||
continue;
|
||||
}
|
||||
let offset = pieces[0].length;
|
||||
const parameters = {};
|
||||
let matches = true;
|
||||
for (let i = 1; i < pieces.length; i += 2) {
|
||||
const delimiter = pieces[i + 1];
|
||||
const last = i + 2 >= pieces.length;
|
||||
const end = last
|
||||
? text.endsWith(delimiter)
|
||||
? text.length - delimiter.length
|
||||
: -1
|
||||
: text.indexOf(delimiter, offset);
|
||||
if (end < 0 || end - offset > 500) {
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
parameters[pieces[i]] = text.slice(offset, end);
|
||||
offset = end + delimiter.length;
|
||||
}
|
||||
if (!matches || offset !== text.length) {
|
||||
continue;
|
||||
}
|
||||
translated = catalog[source].replace(/\{p\d+\}/g, (key) =>
|
||||
translate(parameters[key] ?? key, depth + 1),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (translated === undefined) {
|
||||
const prefix = /^(\d+\s*\/\s*\d+\s*·\s*)(.+)$/u.exec(text);
|
||||
if (prefix && depth < 2) {
|
||||
translated = prefix[1] + translate(prefix[2], depth + 1);
|
||||
}
|
||||
}
|
||||
if (translated === undefined) {
|
||||
const match =
|
||||
/^(.*?)(\s*[:.!?—–·→←↑↓↗↙↘↖↻↺✓✗]\s*|\s+\d+(?:\s*\/\s*\d+)?\s*)$/u.exec(
|
||||
text,
|
||||
);
|
||||
if (match && catalog[match[1]] !== undefined) {
|
||||
translated = catalog[match[1]] + match[2];
|
||||
}
|
||||
}
|
||||
if (translated === undefined) {
|
||||
const amount = /^(.*?[$€£◈])(\d+(?:[.,]\d+)?)$/.exec(text);
|
||||
if (amount && catalog[amount[1]] !== undefined) {
|
||||
translated = catalog[amount[1]] + amount[2];
|
||||
}
|
||||
}
|
||||
if (translated === undefined) {
|
||||
translated = text;
|
||||
}
|
||||
if (cache.size > 5000) {
|
||||
cache.clear();
|
||||
}
|
||||
cache.set(text, translated);
|
||||
return (
|
||||
value.slice(0, value.indexOf(value.trimStart())) +
|
||||
translated +
|
||||
value.slice(value.trimEnd().length)
|
||||
);
|
||||
}
|
||||
prepare();
|
||||
return {
|
||||
translate,
|
||||
get locale() {
|
||||
return locale;
|
||||
},
|
||||
setLocale(value) {
|
||||
const next = resolveLocale(value);
|
||||
if (next === locale) {
|
||||
return false;
|
||||
}
|
||||
locale = next;
|
||||
prepare();
|
||||
return true;
|
||||
},
|
||||
setNames(values) {
|
||||
const next = new Set(
|
||||
values.filter((value) => typeof value === "string").map(normalize),
|
||||
);
|
||||
if (
|
||||
next.size === names.size &&
|
||||
[...next].every((name) => names.has(name))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
names = next;
|
||||
cache.clear();
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Only presentation text is changed. Never translate player input or rewrite game state.
|
||||
export function mountLocalization(target, catalogs, initialLocale = "en") {
|
||||
const translator = createTranslator(catalogs, initialLocale);
|
||||
const originals = new WeakMap();
|
||||
const attributes = ["title", "aria-label", "placeholder", "alt"];
|
||||
const excluded =
|
||||
'script,style,code,pre,[contenteditable="true"],[translate="no"],[data-bgs-player],[data-message-id],.chat-message-text,.chat-message-body,.chat-content,.message-text,.chat-author,.chat-segment';
|
||||
let destroyed = false;
|
||||
function apply(node, attribute) {
|
||||
const element = node.nodeType === 3 ? node.parentElement : node;
|
||||
if (!element || element.closest?.(excluded)) {
|
||||
return;
|
||||
}
|
||||
const value = attribute ? node.getAttribute(attribute) : node.data;
|
||||
if (typeof value !== "string") {
|
||||
return;
|
||||
}
|
||||
let record = originals.get(node);
|
||||
if (!record) {
|
||||
record = new Map();
|
||||
originals.set(node, record);
|
||||
}
|
||||
const key = attribute ?? "text";
|
||||
const previous = record.get(key);
|
||||
const source = previous?.output === value ? previous.source : value;
|
||||
const output = translator.translate(source);
|
||||
record.set(key, { source, output });
|
||||
if (value !== output) {
|
||||
if (attribute) {
|
||||
node.setAttribute(attribute, output);
|
||||
} else {
|
||||
node.data = output;
|
||||
}
|
||||
}
|
||||
}
|
||||
function visit(node) {
|
||||
if (destroyed) {
|
||||
return;
|
||||
}
|
||||
if (node.nodeType === 3) {
|
||||
apply(node);
|
||||
return;
|
||||
}
|
||||
if (node.nodeType !== 1 && node !== target) {
|
||||
return;
|
||||
}
|
||||
if (node.matches?.(excluded)) {
|
||||
return;
|
||||
}
|
||||
for (const attr of attributes) {
|
||||
if (node.hasAttribute?.(attr)) {
|
||||
apply(node, attr);
|
||||
}
|
||||
}
|
||||
if (node.matches?.("input,textarea")) {
|
||||
return;
|
||||
}
|
||||
for (const child of node.childNodes ?? []) {
|
||||
visit(child);
|
||||
}
|
||||
}
|
||||
const observer = new MutationObserver((records) => {
|
||||
for (const record of records) {
|
||||
if (record.type === "characterData") {
|
||||
apply(record.target);
|
||||
} else if (record.type === "attributes") {
|
||||
apply(record.target, record.attributeName);
|
||||
} else {
|
||||
for (const node of record.addedNodes) {
|
||||
visit(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
observer.observe(target, {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
characterData: true,
|
||||
attributes: true,
|
||||
attributeFilter: attributes,
|
||||
});
|
||||
function refresh() {
|
||||
target.lang = translator.locale;
|
||||
visit(target);
|
||||
}
|
||||
refresh();
|
||||
return {
|
||||
translate: translator.translate,
|
||||
get locale() {
|
||||
return translator.locale;
|
||||
},
|
||||
setLocale(locale) {
|
||||
if (translator.setLocale(locale)) {
|
||||
refresh();
|
||||
}
|
||||
},
|
||||
setNames(names) {
|
||||
if (translator.setNames(names)) {
|
||||
refresh();
|
||||
}
|
||||
},
|
||||
setState(state) {
|
||||
const players = state?.players ?? state?.game?.players;
|
||||
if (players && typeof players === "object") {
|
||||
if (
|
||||
translator.setNames(
|
||||
Object.values(players).flatMap((player) => [
|
||||
player?.name,
|
||||
player?.username,
|
||||
]),
|
||||
)
|
||||
) {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
},
|
||||
refresh,
|
||||
destroy() {
|
||||
destroyed = true;
|
||||
observer.disconnect();
|
||||
},
|
||||
};
|
||||
}
|
||||
2284
client/js/src/localization/vi.json
Normal file
2284
client/js/src/localization/vi.json
Normal file
File diff suppressed because it is too large
Load diff
2284
client/js/src/localization/zh-TW.json
Normal file
2284
client/js/src/localization/zh-TW.json
Normal file
File diff suppressed because it is too large
Load diff
154
client/js/src/localized-text.js
Normal file
154
client/js/src/localized-text.js
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
import { catalogs } from "./localization";
|
||||
import { createTranslator, resolveLocale } from "./localization/runtime";
|
||||
|
||||
const translator = createTranslator(catalogs);
|
||||
const canvas = document.createElement("canvas");
|
||||
const context = canvas.getContext("2d", { willReadFrequently: true });
|
||||
const fonts = new Map();
|
||||
const measurements = new Map();
|
||||
let revision = 0;
|
||||
let locale = "en";
|
||||
let family = "sans-serif";
|
||||
let pendingLocale = 0;
|
||||
|
||||
async function loadFont(name, url) {
|
||||
if (!fonts.has(name))
|
||||
fonts.set(
|
||||
name,
|
||||
new FontFace(name, `url("${url}")`).load().then((font) => {
|
||||
document.fonts.add(font);
|
||||
}),
|
||||
);
|
||||
return fonts.get(name);
|
||||
}
|
||||
export async function setLocale(value, assets) {
|
||||
const requested = ++pendingLocale;
|
||||
const next = resolveLocale(value);
|
||||
const font =
|
||||
next === "hi"
|
||||
? "Devanagari"
|
||||
: next === "ko"
|
||||
? "Korean"
|
||||
: next === "zh-TW"
|
||||
? "Chinese"
|
||||
: "SourceSans";
|
||||
const file =
|
||||
font === "SourceSans"
|
||||
? "SourceSans3-Regular.ttf"
|
||||
: `localization/${font}.woff2`;
|
||||
await loadFont(`Clash${font}`, new URL(file, assets).href);
|
||||
if (requested !== pendingLocale) return;
|
||||
locale = next;
|
||||
family = `"Clash${font}", sans-serif`;
|
||||
translator.setLocale(locale);
|
||||
revision++;
|
||||
measurements.clear();
|
||||
}
|
||||
export function setPlayers(state) {
|
||||
try {
|
||||
const parsed = typeof state === "string" ? JSON.parse(state) : state;
|
||||
if (
|
||||
translator.setNames(
|
||||
(parsed?.players ?? []).flatMap((player) => [
|
||||
player.name,
|
||||
player.username,
|
||||
]),
|
||||
)
|
||||
) {
|
||||
revision++;
|
||||
measurements.clear();
|
||||
}
|
||||
} catch {
|
||||
/* Old engine snapshots may omit player names. */
|
||||
}
|
||||
}
|
||||
function metrics(text, size) {
|
||||
const translated = translator.translate(text);
|
||||
const key = `${size}:${translated}`;
|
||||
if (measurements.has(key)) return measurements.get(key);
|
||||
context.font = `${size}px ${family}`;
|
||||
const measured = context.measureText(translated);
|
||||
const left = Math.ceil(Math.max(0, measured.actualBoundingBoxLeft)) + 2;
|
||||
const ascent = Math.ceil(measured.actualBoundingBoxAscent) + 2;
|
||||
const width = Math.max(
|
||||
1,
|
||||
Math.ceil(
|
||||
left + Math.max(measured.width, measured.actualBoundingBoxRight),
|
||||
) + 2,
|
||||
);
|
||||
const height = Math.max(
|
||||
1,
|
||||
Math.ceil(ascent + measured.actualBoundingBoxDescent) + 2,
|
||||
);
|
||||
const result = {
|
||||
translated,
|
||||
width,
|
||||
height,
|
||||
left,
|
||||
ascent,
|
||||
advance: measured.width,
|
||||
glyphHeight:
|
||||
measured.actualBoundingBoxAscent + measured.actualBoundingBoxDescent,
|
||||
glyphAscent: measured.actualBoundingBoxAscent,
|
||||
};
|
||||
if (measurements.size > 2000) measurements.clear();
|
||||
measurements.set(key, result);
|
||||
return result;
|
||||
}
|
||||
window.bgsTranslate = (text) => translator.translate(text);
|
||||
window.bgsTextEnabled = () => locale !== "en";
|
||||
window.bgsTextRevision = () => revision;
|
||||
window.bgsTextMetrics = (text, size) => {
|
||||
const m = metrics(text, size);
|
||||
return new Float32Array([
|
||||
m.width,
|
||||
m.height,
|
||||
m.left,
|
||||
m.ascent,
|
||||
m.advance,
|
||||
m.glyphHeight,
|
||||
m.glyphAscent,
|
||||
]);
|
||||
};
|
||||
window.bgsTextPixels = (text, size) => {
|
||||
const m = metrics(text, size);
|
||||
canvas.width = m.width * 2;
|
||||
canvas.height = m.height * 2;
|
||||
context.scale(2, 2);
|
||||
context.font = `${size}px ${family}`;
|
||||
context.fillStyle = "white";
|
||||
context.fillText(m.translated, m.left, m.ascent);
|
||||
return context.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||
};
|
||||
window.bgsWrapText = (text, width, size) => {
|
||||
const translated = translator.translate(text);
|
||||
const words = new Intl.Segmenter(locale, { granularity: "word" }).segment(
|
||||
translated,
|
||||
);
|
||||
const lines = [];
|
||||
let line = "";
|
||||
for (const { segment } of words) {
|
||||
if (segment.includes("\n")) {
|
||||
lines.push(line.trimEnd());
|
||||
line = "";
|
||||
continue;
|
||||
}
|
||||
if (line && metrics(line + segment, size).advance > width) {
|
||||
lines.push(line.trimEnd());
|
||||
line = "";
|
||||
}
|
||||
if (metrics(segment, size).advance > width) {
|
||||
for (const { segment: character } of new Intl.Segmenter(locale, {
|
||||
granularity: "grapheme",
|
||||
}).segment(segment)) {
|
||||
if (line && metrics(line + character, size).advance > width) {
|
||||
lines.push(line);
|
||||
line = "";
|
||||
}
|
||||
line += character;
|
||||
}
|
||||
} else line += !line ? segment.trimStart() : segment;
|
||||
}
|
||||
if (line) lines.push(line.trimEnd());
|
||||
return JSON.stringify(lines);
|
||||
};
|
||||
|
|
@ -1,32 +1,32 @@
|
|||
import init, {set_wasm} from "../../dist/remote_client";
|
||||
import init, { set_wasm } from "../../dist/remote_client";
|
||||
|
||||
function dynamicallyLoadScript(url, onload) {
|
||||
const script = document.createElement("script");
|
||||
script.onload = onload;
|
||||
script.src = url;
|
||||
const script = document.createElement("script");
|
||||
script.onload = onload;
|
||||
script.src = url;
|
||||
|
||||
document.head.appendChild(script);
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
export async function run({selector, control}) {
|
||||
let wbg = await init();
|
||||
miniquad_add_plugin({
|
||||
register_plugin: (a) => {
|
||||
console.log("register_plugin", a);
|
||||
return (a.wbg = wbg)
|
||||
},
|
||||
on_init: () => {
|
||||
console.log("on_init", wasm_exports);
|
||||
window.clash_control.send_ready()
|
||||
return set_wasm(wasm_exports)
|
||||
},
|
||||
version: "0.0.1",
|
||||
name: "wbg",
|
||||
});
|
||||
const src = document.body.getElementsByTagName("script")[1].src;
|
||||
control.assets_url = src.replace("client.js", "assets/");
|
||||
const url = src.replace("client.js", "client.wasm");
|
||||
console.log("Loading wasm from", url);
|
||||
await load(url);
|
||||
console.log("Loaded wasm");
|
||||
export async function run({ selector, control }) {
|
||||
let wbg = await init();
|
||||
miniquad_add_plugin({
|
||||
register_plugin: (a) => {
|
||||
console.log("register_plugin", a);
|
||||
return (a.wbg = wbg);
|
||||
},
|
||||
on_init: () => {
|
||||
console.log("on_init", wasm_exports);
|
||||
window.clash_control.send_ready();
|
||||
return set_wasm(wasm_exports);
|
||||
},
|
||||
version: "0.0.1",
|
||||
name: "wbg",
|
||||
});
|
||||
const src = document.body.getElementsByTagName("script")[1].src;
|
||||
control.assets_url ||= src.replace("client.js", "assets/");
|
||||
const url = new URL("../client.wasm", control.assets_url).href;
|
||||
console.log("Loading wasm from", url);
|
||||
await load(url);
|
||||
console.log("Loaded wasm");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ impl HandCardObject {
|
|||
pub(crate) fn new(id: HandCard, color: Color, name: &str, description: MultilineText) -> Self {
|
||||
Self {
|
||||
id,
|
||||
name: name.chars().take(17).collect(),
|
||||
name: crate::localization::translate(name),
|
||||
description,
|
||||
color,
|
||||
}
|
||||
|
|
@ -324,7 +324,12 @@ pub(crate) fn objective_card_object(
|
|||
.iter()
|
||||
.find_map(|(i, n)| (i == &id).then_some(n.clone()))
|
||||
})
|
||||
.unwrap_or_else(|| card.objectives.iter().map(|o| o.name.clone()).join(", "));
|
||||
.unwrap_or_else(|| {
|
||||
card.objectives
|
||||
.iter()
|
||||
.map(|o| crate::localization::translate(&o.name))
|
||||
.join(", ")
|
||||
});
|
||||
|
||||
HandCardObject::new(
|
||||
HandCard::ObjectiveCard(id),
|
||||
|
|
|
|||
|
|
@ -591,7 +591,8 @@ impl State {
|
|||
|
||||
#[must_use]
|
||||
pub(crate) fn measure_text(&self, text: &str) -> TextDimensions {
|
||||
measure_text(text, Some(&self.assets.font), FONT_SIZE, 1.0)
|
||||
crate::localization::measure(text, FONT_SIZE)
|
||||
.unwrap_or_else(|| measure_text(text, Some(&self.assets.font), FONT_SIZE, 1.0))
|
||||
}
|
||||
|
||||
pub(crate) fn draw_text(&self, text: &str, x: f32, y: f32) {
|
||||
|
|
@ -599,6 +600,9 @@ impl State {
|
|||
}
|
||||
|
||||
pub(crate) fn draw_text_ex(&self, text: &str, x: f32, y: f32, color: Color, font_size: u16) {
|
||||
if crate::localization::draw(text, font_size, x, y, color) {
|
||||
return;
|
||||
}
|
||||
draw_text_ex(
|
||||
text,
|
||||
x,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ mod hex_ui;
|
|||
mod influence_ui;
|
||||
mod info_ui;
|
||||
mod layout_ui;
|
||||
mod localization;
|
||||
mod log_collector;
|
||||
mod log_ui;
|
||||
mod map_ui;
|
||||
|
|
|
|||
126
client/src/localization.rs
Normal file
126
client/src/localization.rs
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
#[cfg(target_arch = "wasm32")]
|
||||
mod browser {
|
||||
use macroquad::prelude::*;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = window, js_name = bgsTranslate)]
|
||||
pub fn translate(text: &str) -> String;
|
||||
#[wasm_bindgen(js_namespace = window, js_name = bgsWrapText)]
|
||||
pub fn wrap(text: &str, width: f32, size: u16) -> String;
|
||||
#[wasm_bindgen(js_namespace = window, js_name = bgsTextEnabled)]
|
||||
pub fn enabled() -> bool;
|
||||
#[wasm_bindgen(js_namespace = window, js_name = bgsTextRevision)]
|
||||
fn revision() -> u32;
|
||||
#[wasm_bindgen(js_namespace = window, js_name = bgsTextMetrics)]
|
||||
fn metrics(text: &str, size: u16) -> Vec<f32>;
|
||||
#[wasm_bindgen(js_namespace = window, js_name = bgsTextPixels)]
|
||||
fn pixels(text: &str, size: u16) -> Vec<u8>;
|
||||
}
|
||||
|
||||
struct TextImage {
|
||||
texture: Texture2D,
|
||||
metrics: Vec<f32>,
|
||||
}
|
||||
#[derive(Default)]
|
||||
struct Cache {
|
||||
revision: u32,
|
||||
entries: HashMap<(String, u16), TextImage>,
|
||||
}
|
||||
thread_local! { static CACHE: RefCell<Cache> = RefCell::new(Cache::default()); }
|
||||
|
||||
pub fn measure(text: &str, size: u16) -> TextDimensions {
|
||||
let m = metrics(text, size);
|
||||
TextDimensions {
|
||||
width: m[4],
|
||||
height: m[5],
|
||||
offset_y: m[6],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(text: &str, size: u16, x: f32, y: f32, color: Color) {
|
||||
CACHE.with(|cache| {
|
||||
let mut cache = cache.borrow_mut();
|
||||
let current = revision();
|
||||
if cache.revision != current || cache.entries.len() > 1000 {
|
||||
cache.entries.clear();
|
||||
cache.revision = current;
|
||||
}
|
||||
let entry = cache
|
||||
.entries
|
||||
.entry((text.to_owned(), size))
|
||||
.or_insert_with(|| {
|
||||
let m = metrics(text, size);
|
||||
let texture = Texture2D::from_rgba8(
|
||||
(m[0] * 2.0) as u16,
|
||||
(m[1] * 2.0) as u16,
|
||||
&pixels(text, size),
|
||||
);
|
||||
texture.set_filter(FilterMode::Linear);
|
||||
TextImage {
|
||||
texture,
|
||||
metrics: m,
|
||||
}
|
||||
});
|
||||
let m = &entry.metrics;
|
||||
draw_texture_ex(
|
||||
&entry.texture,
|
||||
x - m[2],
|
||||
y - m[3],
|
||||
color,
|
||||
DrawTextureParams {
|
||||
dest_size: Some(vec2(m[0], m[1])),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn translate(text: &str) -> String {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
browser::translate(text)
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
text.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn measure(text: &str, size: u16) -> Option<macroquad::prelude::TextDimensions> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if browser::enabled() {
|
||||
return Some(browser::measure(text, size));
|
||||
}
|
||||
let _ = (text, size);
|
||||
None
|
||||
}
|
||||
|
||||
pub(crate) fn draw(
|
||||
text: &str,
|
||||
size: u16,
|
||||
x: f32,
|
||||
y: f32,
|
||||
color: macroquad::prelude::Color,
|
||||
) -> bool {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if browser::enabled() {
|
||||
browser::draw(text, size, x, y, color);
|
||||
return true;
|
||||
}
|
||||
let _ = (text, size, x, y, color);
|
||||
false
|
||||
}
|
||||
|
||||
pub(crate) fn wrap(text: &str, width: f32, size: u16) -> Option<Vec<String>> {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if browser::enabled() {
|
||||
return serde_json::from_str(&browser::wrap(text, width, size)).ok();
|
||||
}
|
||||
let _ = (text, width, size);
|
||||
None
|
||||
}
|
||||
|
|
@ -325,6 +325,13 @@ pub(crate) fn multiline_label(
|
|||
len: f32,
|
||||
mut print: impl FnMut(usize, &str),
|
||||
) {
|
||||
if let Some(lines) = crate::localization::wrap(label, len, crate::layout_ui::FONT_SIZE) {
|
||||
for (i, line) in lines.iter().enumerate() {
|
||||
print(i, line);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let label = crate::localization::translate(label);
|
||||
let mut line = String::new();
|
||||
let mut i = 0;
|
||||
label.split(' ').for_each(|s| {
|
||||
|
|
|
|||
24
scripts/build-localization-fonts.py
Normal file
24
scripts/build-localization-fonts.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
"""Regenerate browser font subsets. Requires fonttools[woff] and the Noto fonts."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from fontTools import subset
|
||||
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')
|
||||
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)]:
|
||||
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)
|
||||
processor = subset.Subsetter(options=subset.Options())
|
||||
processor.populate(text=text)
|
||||
processor.subset(font)
|
||||
font.flavor = 'woff2'
|
||||
font.save(output / f'{name}.woff2')
|
||||
print(f'{name}: {(output / f"{name}.woff2").stat().st_size} bytes')
|
||||
49
scripts/check-locales.mjs
Normal file
49
scripts/check-locales.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
const directory = process.argv[2];
|
||||
if (!directory) {
|
||||
throw Error("Usage: node check-locales.mjs <localization directory>");
|
||||
}
|
||||
const source = JSON.parse(await readFile(join(directory, "en.json"), "utf8"));
|
||||
const placeholders = (text) =>
|
||||
[...text.matchAll(/\{\w+\}/g)].map((match) => match[0]).sort();
|
||||
const locales = [
|
||||
"en",
|
||||
"de",
|
||||
"fr",
|
||||
"pl",
|
||||
"ro",
|
||||
"el",
|
||||
"hi",
|
||||
"ru",
|
||||
"da",
|
||||
"pt-BR",
|
||||
"ko",
|
||||
"zh-TW",
|
||||
"vi",
|
||||
"it",
|
||||
"nl",
|
||||
];
|
||||
for (const locale of locales) {
|
||||
const catalog = JSON.parse(
|
||||
await readFile(join(directory, `${locale}.json`), "utf8"),
|
||||
);
|
||||
assert.deepEqual(
|
||||
Object.keys(catalog).sort(),
|
||||
Object.keys(source).sort(),
|
||||
`${locale}: missing or extra strings`,
|
||||
);
|
||||
for (const [key, text] of Object.entries(catalog)) {
|
||||
assert.equal(typeof text, "string", `${locale}: ${key}`);
|
||||
assert.ok(text.trim(), `${locale}: empty translation of ${key}`);
|
||||
assert.deepEqual(
|
||||
placeholders(text),
|
||||
placeholders(source[key]),
|
||||
`${locale}: changed placeholders in ${key}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
`${locales.length} languages × ${Object.keys(source).length} messages validated`,
|
||||
);
|
||||
69
scripts/localization.test.mjs
Normal file
69
scripts/localization.test.mjs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { readFile } from "node:fs/promises";
|
||||
const source = await readFile(
|
||||
new URL("../client/js/src/localization/runtime.js", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
const { createTranslator, resolveLocale } = await import(
|
||||
"data:text/javascript;base64," + Buffer.from(source).toString("base64")
|
||||
);
|
||||
const catalogs = {
|
||||
nl: {
|
||||
Draw: "Tekenen",
|
||||
"Your cash: $": "Je geld: $",
|
||||
Ore: "Erts",
|
||||
east: "oost",
|
||||
"{p0} · ◈ {p1}": "{p0} · ◈ {p1}",
|
||||
Round: "Ronde",
|
||||
"Build {p0} for {p1}": "Bouw voor {p1}: {p0}",
|
||||
"{p0} buys {p1}": "{p0} koopt {p1}",
|
||||
"Make money by trading": "Verdien geld door te handelen",
|
||||
"Gain {p0} points{p1}": "Krijg {p0} punten{p1}",
|
||||
},
|
||||
fr: { Round: "Manche" },
|
||||
};
|
||||
test("regional language preferences select supported catalogues", () => {
|
||||
assert.equal(resolveLocale("nl-BE"), "nl");
|
||||
assert.equal(resolveLocale("pt-PT"), "pt-BR");
|
||||
assert.equal(resolveLocale("zh-Hant-TW"), "zh-TW");
|
||||
assert.equal(resolveLocale("zh-CN"), "en");
|
||||
assert.equal(resolveLocale(undefined), "en");
|
||||
});
|
||||
test("dynamic values are reordered while player names stay unchanged", () => {
|
||||
const t = createTranslator(catalogs, "nl");
|
||||
t.setNames(["Draw"]);
|
||||
assert.equal(t.translate("Draw buys 3"), "Draw koopt 3");
|
||||
assert.equal(t.translate("Build 2 for 10"), "Bouw voor 10: 2");
|
||||
assert.equal(t.translate("Draw"), "Draw");
|
||||
assert.equal(t.translate("Gain 2 points"), "Krijg 2 punten");
|
||||
});
|
||||
test("tutorial numbering and whitespace survive translation", () => {
|
||||
const t = createTranslator(catalogs, "nl");
|
||||
assert.equal(
|
||||
t.translate(" 1/5 · Make money by trading\n"),
|
||||
" 1/5 · Verdien geld door te handelen\n",
|
||||
);
|
||||
assert.equal(t.translate("Round 2"), "Ronde 2");
|
||||
assert.equal(t.translate("Unknown sentence"), "Unknown sentence");
|
||||
});
|
||||
test("language changes clear caches and preserve the English fallback", () => {
|
||||
const t = createTranslator(catalogs, "nl");
|
||||
assert.equal(t.translate("Round"), "Ronde");
|
||||
t.setLocale("fr");
|
||||
assert.equal(t.translate("Round"), "Manche");
|
||||
t.setLocale("en");
|
||||
assert.equal(t.translate("Round"), "Round");
|
||||
});
|
||||
|
||||
test("icon-separated values and uppercase labels are localized", () => {
|
||||
const t = createTranslator(catalogs, "nl");
|
||||
assert.equal(t.translate("Ore · ◈ 10"), "Erts · ◈ 10");
|
||||
assert.equal(t.translate("EAST"), "OOST");
|
||||
});
|
||||
|
||||
test("decorative arrows and attached currency values keep their meaning", () => {
|
||||
const t = createTranslator(catalogs, "nl");
|
||||
assert.equal(t.translate("Draw →"), "Tekenen →");
|
||||
assert.equal(t.translate("Your cash: $20"), "Je geld: $20");
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue