fix: allow theme fonts for some languages

This commit is contained in:
Ryan Dowling 2022-07-29 18:51:55 +10:00
parent 78cba98bf3
commit a173727bce
No known key found for this signature in database
GPG key ID: 5539FCDB88950EFD
6 changed files with 62 additions and 11 deletions

3
.gitignore vendored
View file

@ -26,3 +26,6 @@ testLauncher/
java_pid*.hprof
*.log
mockserver_keystore_*
# crowdin config
crowdin.yml

View file

@ -13,6 +13,7 @@ This changelog only contains the changes that are unreleased. For changes for in
- Noisy logs around images for instance/server cards
- Some incorrect colours on light themes
- Issue with main Forge library not downloading correctly from our CDN
- Allow theme fonts for some languages
### Misc
- Remove headless dependency from debian package

View file

@ -19,7 +19,7 @@ package com.atlauncher.data;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -30,21 +30,59 @@ import org.mini2Dx.gettext.PoFile;
import com.atlauncher.App;
import com.atlauncher.evnt.manager.RelocalizationManager;
import com.atlauncher.managers.LogManager;
import com.atlauncher.utils.Utils;
public class Language {
public final static List<Locale> locales = new ArrayList<>();
public final static Map<String, Locale> languages = new HashMap<>();
public final static Map<String, Locale> languages = new LinkedHashMap<>();
public final static List<Locale> localesWithoutFonts = new ArrayList<>();
public static String selected = Locale.ENGLISH.getDisplayName();
public static Locale selectedLocale = Locale.ENGLISH;
// add in the languages we have support for
static {
locales.add(Locale.ENGLISH);
locales.add(Locale.ENGLISH); // English
locales.add(new Locale("af", "ZA")); // Afrikaans
locales.add(new Locale("ar", "SA")); // Arabic
locales.add(new Locale("ca", "ES")); // Catalan
locales.add(new Locale("zh", "CN")); // Chinese Simplified
locales.add(new Locale("zh", "TW")); // Chinese Traditional
locales.add(new Locale("cs", "CZ")); // Czech
locales.add(new Locale("da", "DK")); // Danish
locales.add(new Locale("nl", "NL")); // Dutch
locales.add(new Locale("fi", "FI")); // Finnish
locales.add(new Locale("fr", "FR")); // French
locales.add(new Locale("de", "DE")); // German
locales.add(new Locale("el", "GR")); // Greek
locales.add(new Locale("he", "IL")); // Hebrew
locales.add(new Locale("hu", "HU")); // Hungarian
locales.add(new Locale("it", "IT")); // Italian
locales.add(new Locale("ja", "JP")); // Japanese
locales.add(new Locale("ko", "KR")); // Korean
locales.add(new Locale("no", "NO")); // Norwegian
locales.add(new Locale("pl", "PL")); // Polish
locales.add(new Locale("pt", "PT")); // Portuguese
locales.add(new Locale("pt", "BR")); // Portuguese, Brazilian
locales.add(new Locale("ro", "RO")); // Romanian
locales.add(new Locale("ru", "RU")); // Russian
locales.add(new Locale("sr", "SP")); // Serbian
locales.add(new Locale("es", "ES")); // Spanish
locales.add(new Locale("sv", "SE")); // Swedish
locales.add(new Locale("tr", "TR")); // Turkish
locales.add(new Locale("uk", "UA")); // Ukranian
localesWithoutFonts.add(new Locale("ar", "SA"));
localesWithoutFonts.add(new Locale("zh", "CN"));
localesWithoutFonts.add(new Locale("zh", "TW"));
localesWithoutFonts.add(new Locale("he", "IL"));
localesWithoutFonts.add(new Locale("ja", "JP"));
localesWithoutFonts.add(new Locale("ko", "KR"));
}
public static void init() throws IOException {
for (Locale locale : locales) {
if (App.class.getResourceAsStream("/assets/lang/" + locale.toString() + ".po") != null) {
System.out.println(locale.toString());
if (Utils.getResourceInputStream(
"/assets/lang/" + locale.getLanguage() + "-" + locale.getCountry() + ".po") != null) {
languages.put(locale.getDisplayName(), locale);
LogManager.debug("Loaded language " + locale.getDisplayName() + " with key of " + locale);
}
@ -71,7 +109,8 @@ public class Language {
if (locale != Locale.ENGLISH) {
try {
GetText.add(
new PoFile(locale, App.class.getResourceAsStream("/assets/lang/" + locale.toString() + ".po")));
new PoFile(locale, App.class.getResourceAsStream(
"/assets/lang/" + locale.getLanguage() + "-" + locale.getCountry() + ".po")));
} catch (IOException e) {
LogManager.logStackTrace("Failed loading language po file for " + language, e);
locale = Locale.ENGLISH;
@ -79,6 +118,8 @@ public class Language {
}
}
selectedLocale = locale;
GetText.setLocale(locale);
RelocalizationManager.post();
}

View file

@ -92,7 +92,8 @@ public class GeneralSettingsTab extends AbstractSettingsTab {
JPanel languagePanel = new JPanel();
languagePanel.setLayout(new BoxLayout(languagePanel, BoxLayout.X_AXIS));
language = new JComboBox<>(Language.locales.stream().map(Locale::getDisplayName).toArray(String[]::new));
language = new JComboBox<>(
Language.locales.stream().map(Locale::getDisplayName).toArray(String[]::new));
language.setSelectedItem(Language.selected);
languagePanel.add(language);

View file

@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import com.atlauncher.App;
import com.atlauncher.data.Language;
import com.atlauncher.managers.LogManager;
import com.atlauncher.utils.Resources;
import com.formdev.flatlaf.FlatDarculaLaf;
@ -51,11 +52,11 @@ public class ATLauncherLaf extends FlatLaf {
}
/**
* If user has disabled custom fonts or is using a non English language, then we
* should be using the base "sansserif" font.
* If user has disabled custom fonts or is using a language without a font, then
* we should be using the base "sansserif" font to let the OS font take over.
*/
private static boolean useBaseFont() {
return App.settings.disableCustomFonts || !App.settings.language.equalsIgnoreCase("English");
return App.settings.disableCustomFonts || Language.localesWithoutFonts.contains(Language.selectedLocale);
}
public Font getNormalFont() {
@ -68,7 +69,7 @@ public class ATLauncherLaf extends FlatLaf {
public Font getBoldFont() {
if (useBaseFont()) {
return Resources.makeFont("sansserif").deriveFont(Font.PLAIN, 12f);
return Resources.makeFont("sansserif").deriveFont(Font.BOLD, 12f);
} else {
return Resources.makeFont(defaultFontName).deriveFont(Font.BOLD, 12f);
}

View file

@ -61,6 +61,10 @@ public final class Resources {
return f;
} else {
URL url = Resources.class.getResource("/assets/font/" + name + ".ttf");
if (url == null) {
url = Resources.class.getResource("/assets/font/" + name + ".otf");
}
if (url == null) {
LogManager.error("Cannot find font " + name);
return new Font("Sans-Serif", Font.PLAIN, 0);