2021-06-29 09:41:08 +00:00
|
|
|
package the.bytecode.club.bytecodeviewer.translation;
|
|
|
|
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
import org.apache.commons.collections4.map.HashedMap;
|
|
|
|
import org.apache.commons.collections4.map.LinkedMap;
|
|
|
|
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
|
|
|
import the.bytecode.club.bytecodeviewer.Resources;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
import java.util.LinkedHashSet;
|
2021-06-29 09:41:08 +00:00
|
|
|
|
2021-07-07 05:56:29 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
|
|
|
|
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2021-06-29 09:41:08 +00:00
|
|
|
/**
|
|
|
|
* All of the supported languages
|
|
|
|
*
|
2021-07-08 09:32:09 +00:00
|
|
|
* TODO: Hindi, Bengali, Korean, Thai & Javanese need fonts to be supplied for them to show.
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
* The default font should be saved so it can be restored for latin-character based languages
|
|
|
|
*
|
2021-06-29 09:41:08 +00:00
|
|
|
* @author Konloch
|
|
|
|
* @since 6/28/2021
|
|
|
|
*/
|
|
|
|
public enum Language
|
|
|
|
{
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
ARABIC("/translations/arabic.json", "عربى", "English", "ar"),
|
2021-07-07 09:00:14 +00:00
|
|
|
ENGLISH("/translations/english.json", "English", "English", "en"),
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
FARSI("/translations/farsi.json", "فارسی ", "English", "fa"),
|
|
|
|
FINNISH("/translations/finnish.json", "Suomen Kieli", "English", "fi"),
|
2021-07-07 09:00:14 +00:00
|
|
|
FRENCH("/translations/french.json", "Français", "English", "fr"),
|
|
|
|
GERMAN("/translations/german.json", "Deutsch", "German", "de"),
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
GEORGIAN("/translations/georgian.json", "ქართული ენა", "English", "ka"),
|
|
|
|
GREEK("/translations/greek.json", "ελληνικά", "English", "el"),
|
|
|
|
HAUSA("/translations/hausa.json", "Hausa", "English", "ha"),
|
|
|
|
HEBREW("/translations/hebrew.json", "עִבְרִית\u200E", "English", "iw", "he"),
|
2021-07-07 09:00:14 +00:00
|
|
|
//HINDI("/translations/hindi.json", "हिंदी", "English", "hi"),
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
//BENGALI("/translations/bengali.json", "বাংলা", "English", "bn"),
|
|
|
|
HUNGARIAN("/translations/hungarian.json", "Magyar Nyelv", "English", "hu"),
|
|
|
|
INDONESIAN("/translations/indonesian.json", "bahasa Indonesia", "English", "id"),
|
|
|
|
ITALIAN("/translations/italian.json", "Italiano", "English", "it"),
|
2021-07-07 09:00:14 +00:00
|
|
|
JAPANESE("/translations/japanese.json", "日本語", "English", "ja"),
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
//JAVANESE("/translations/javanese.json", "ꦧꦱꦗꦮ", "English", "jw", "jv"),
|
2021-07-08 09:32:09 +00:00
|
|
|
//KOREAN("/translations/korean.json", "Korean", "English", "ko"),
|
2021-07-07 09:00:14 +00:00
|
|
|
MALAY("/translations/malay.json", "Bahasa Melayu", "English", "ms"),
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
MANDARIN("/translations/mandarin.json", "普通话", "Mandarin", "zh-CN", "zh_cn", "zh"),
|
|
|
|
NEDERLANDS("/translations/nederlands.json", "Nederlands", "English", "nl"), //dutch
|
|
|
|
NORWEGIAN("/translations/norwegian.json", "Norsk", "English", "no"),
|
|
|
|
POLISH("/translations/polish.json", "Polski", "English", "pl"),
|
2021-07-07 09:00:14 +00:00
|
|
|
PORTUGUESE("/translations/portuguese.json", "Português", "English", "pt"),
|
|
|
|
RUSSIAN("/translations/russian.json", "русский", "English", "ru"),
|
|
|
|
SPANISH("/translations/spanish.json", "Español", "English", "es"),
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
SWAHILI("/translations/swahili.json", "Kiswahili", "English", "sw"),
|
|
|
|
SWEDISH("/translations/swedish.json", "svenska", "English", "sv"),
|
|
|
|
//THAI("/translations/thai.json", "ภาษาไทย", "English", "th"),
|
|
|
|
TURKISH("/translations/turkish.json", "Türkçe", "English", "tr"),
|
|
|
|
UKRAINIAN("/translations/ukrainian.json", "украї́нська мо́ва", "English", "uk"),
|
|
|
|
VIETNAMESE("/translations/vietnamese.json", "Tiếng Việt", "English", "vi"),
|
2021-06-29 09:41:08 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
private static final HashedMap<String, Language> languageCodeLookup;
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
languageCodeLookup = new HashedMap<>();
|
|
|
|
for(Language l : values())
|
|
|
|
l.languageCode.forEach((langCode)->
|
|
|
|
languageCodeLookup.put(langCode, l));
|
|
|
|
}
|
|
|
|
|
|
|
|
private final String resourcePath;
|
|
|
|
private final String readableName;
|
2021-07-07 09:00:14 +00:00
|
|
|
private final String htmlIdentifier;
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
private final LinkedHashSet<String> languageCode;
|
2021-06-29 09:41:08 +00:00
|
|
|
|
2021-07-07 09:00:14 +00:00
|
|
|
Language(String resourcePath, String readableName, String htmlIdentifier, String... languageCodes)
|
2021-06-29 09:41:08 +00:00
|
|
|
{
|
|
|
|
this.resourcePath = resourcePath;
|
|
|
|
this.readableName = readableName;
|
2021-07-07 09:00:14 +00:00
|
|
|
this.htmlIdentifier = htmlIdentifier.toLowerCase();
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
this.languageCode = new LinkedHashSet<>(Arrays.asList(languageCodes));
|
2021-06-29 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void loadLanguage() throws IOException
|
|
|
|
{
|
2021-06-29 16:11:26 +00:00
|
|
|
printMissingLanguageKeys();
|
|
|
|
|
2021-06-29 09:41:08 +00:00
|
|
|
HashMap<String, String> translationMap = BytecodeViewer.gson.fromJson(
|
2021-07-01 21:54:10 +00:00
|
|
|
Resources.loadResourceAsString(resourcePath),
|
2021-06-29 09:41:08 +00:00
|
|
|
new TypeToken<HashMap<String, String>>(){}.getType());
|
|
|
|
|
|
|
|
for(Translation translation : Translation.values())
|
|
|
|
{
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
TranslatedComponentReference text = translation.getTranslatedComponentReference();
|
2021-06-29 09:41:08 +00:00
|
|
|
|
|
|
|
//skip translating if the language config is missing the translation key
|
|
|
|
if(!translationMap.containsKey(text.key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//update translation text value
|
|
|
|
text.value = translationMap.get(text.key);
|
|
|
|
|
2021-07-07 09:00:14 +00:00
|
|
|
//translate constant strings
|
|
|
|
try {
|
|
|
|
TranslatedStrings str = TranslatedStrings.valueOf(text.key);
|
|
|
|
str.setText(text.value);
|
|
|
|
} catch (IllegalArgumentException e) { }
|
|
|
|
|
2021-06-29 09:41:08 +00:00
|
|
|
//check if translation key has been assigned to a component,
|
|
|
|
//on fail print an error alerting the devs
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
if(translation.getTranslatedComponentReference().runOnUpdate.isEmpty())
|
2021-07-07 10:39:29 +00:00
|
|
|
//&& TranslatedStrings.nameSet.contains(translation.name()))
|
2021-06-29 09:41:08 +00:00
|
|
|
{
|
|
|
|
System.err.println("Translation Reference " + translation.name() + " is missing component attachment, skipping...");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//trigger translation event
|
More Translations
Most components should be translated. All of the components that were hardcoded for English now work with translations.
All of the translations now include any missing translation keys.
Added translations for: Farsi, Finnish, Greek, Indonesian, Bengali, Italian, Korean, Dutch, Polish, Swedish, Thai, Hebrew, Turkish, Ukrainian, Hungarian, Georgian, Javanese, Hausa, Swahili, Norwegian & Vietnamese
2021-07-08 08:22:39 +00:00
|
|
|
translation.getTranslatedComponentReference().translate();
|
2021-06-29 09:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
// When adding new Translation Components:
|
|
|
|
// 1) start by adding the strings into the english.json
|
2021-06-29 16:11:26 +00:00
|
|
|
// 2) run this function to get the keys and add them into the Translation.java enum
|
2021-06-29 09:41:08 +00:00
|
|
|
// 3) replace the swing component (MainViewerGUI) with a translated component
|
|
|
|
// and reference the correct translation key
|
|
|
|
// 4) add the translation key to the rest of the translation files
|
2021-06-29 16:11:26 +00:00
|
|
|
public void printMissingLanguageKeys() throws IOException
|
2021-06-29 09:41:08 +00:00
|
|
|
{
|
|
|
|
if(this != ENGLISH)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LinkedMap<String, String> translationMap = BytecodeViewer.gson.fromJson(
|
2021-07-01 21:54:10 +00:00
|
|
|
Resources.loadResourceAsString(resourcePath),
|
2021-06-29 09:41:08 +00:00
|
|
|
new TypeToken<LinkedMap<String, String>>(){}.getType());
|
|
|
|
|
2021-06-29 16:11:26 +00:00
|
|
|
HashSet<String> existingKeys = new HashSet<>();
|
|
|
|
for(Translation t : Translation.values())
|
|
|
|
existingKeys.add(t.name());
|
|
|
|
|
2021-06-29 09:41:08 +00:00
|
|
|
for(String key : translationMap.keySet())
|
2021-07-07 09:00:14 +00:00
|
|
|
if(!existingKeys.contains(key))
|
2021-06-29 16:11:26 +00:00
|
|
|
System.err.println(key + ",");
|
2021-06-29 09:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getResourcePath()
|
|
|
|
{
|
|
|
|
return resourcePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HashSet<String> getLanguageCode()
|
|
|
|
{
|
|
|
|
return languageCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getReadableName()
|
|
|
|
{
|
|
|
|
return readableName;
|
|
|
|
}
|
|
|
|
|
2021-07-07 09:00:14 +00:00
|
|
|
public String getHTMLPath(String identifier)
|
|
|
|
{
|
|
|
|
return "translations/html/" + identifier + "." + htmlIdentifier + ".html";
|
|
|
|
}
|
|
|
|
|
2021-06-29 09:41:08 +00:00
|
|
|
public static HashedMap<String, Language> getLanguageCodeLookup()
|
|
|
|
{
|
|
|
|
return languageCodeLookup;
|
|
|
|
}
|
|
|
|
}
|