Skip to content

Commit f332083

Browse files
committed
Rewrite i18n implementation
1 parent a094d4f commit f332083

17 files changed

+182
-23
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<name>NS-USBloader</name>
99

1010
<artifactId>ns-usbloader</artifactId>
11-
<version>4.1-SNAPSHOT</version>
11+
<version>4.2-SNAPSHOT</version>
1212

1313
<url>https://github.com/developersu/ns-usbloader/</url>
1414
<description>

src/main/java/nsusbloader/AppPreferences.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ public class AppPreferences {
2727
private static final AppPreferences INSTANCE = new AppPreferences();
2828
public static AppPreferences getInstance() { return INSTANCE; }
2929

30-
private Preferences preferences;
30+
private final Preferences preferences;
31+
private final Locale locale;
3132

32-
private AppPreferences(){ preferences = Preferences.userRoot().node("NS-USBloader"); }
33+
private AppPreferences(){
34+
this.preferences = Preferences.userRoot().node("NS-USBloader");
35+
String localeCode = preferences.get("locale", Locale.getDefault().toString());
36+
this.locale = new Locale(localeCode.substring(0, 2), localeCode.substring(3, 5));
37+
}
3338

3439
public String getTheme(){
3540
String theme = preferences.get("THEME", "/res/app_dark.css"); // Don't let user to change settings manually
@@ -59,6 +64,10 @@ public String getNetUsb(){
5964
public String getRecent(){ return preferences.get("RECENT", System.getProperty("user.home")); }
6065
public void setRecent(String path){ preferences.put("RECENT", path); }
6166
//------------ SETTINGS ------------------//
67+
68+
public Locale getLocale(){ return this.locale; }
69+
public void setLocale(String langStr){ preferences.put("locale", langStr); }
70+
6271
public boolean getNsIpValidationNeeded() {return preferences.getBoolean("NSIPVALIDATION", true);}
6372
public void setNsIpValidationNeeded(boolean need){preferences.putBoolean("NSIPVALIDATION", need);}
6473

@@ -96,9 +105,6 @@ public String getHostPort(){
96105
public boolean getTfXCI(){return preferences.getBoolean("TF_XCI", true);}
97106
public void setTfXCI(boolean prop){ preferences.putBoolean("TF_XCI", prop); }
98107

99-
public String getLanguage(){return preferences.get("USR_LANG", Locale.getDefault().getISO3Language());}
100-
public void setLanguage(String langStr){preferences.put("USR_LANG", langStr);}
101-
102108
public boolean getNspFileFilterGL(){return preferences.getBoolean("GL_NSP_FILTER", false); }
103109
public void setNspFileFilterGL(boolean prop){preferences.putBoolean("GL_NSP_FILTER", prop);}
104110

src/main/java/nsusbloader/Controllers/SettingsController.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import nsusbloader.AppPreferences;
3131
import nsusbloader.ServiceWindow;
3232
import nsusbloader.ModelControllers.UpdatesChecker;
33+
import nsusbloader.UI.LocaleUiStringHolder;
3334
import nsusbloader.Utilities.WindowsDrivers.DriversInstall;
3435

3536
import java.io.File;
@@ -73,7 +74,7 @@ public class SettingsController implements Initializable {
7374
checkForUpdBtn,
7475
drvInstBtn;
7576
@FXML
76-
private ChoiceBox<String> langCB;
77+
private ChoiceBox<LocaleUiStringHolder> langCB;
7778

7879
@FXML
7980
private ChoiceBox<String> glVersionChoiceBox;
@@ -220,8 +221,8 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
220221
tfXciSpprtCb.setSelected(AppPreferences.getInstance().getTfXCI());
221222

222223
// Language settings area
223-
ObservableList<String> langCBObsList = FXCollections.observableArrayList();
224-
langCBObsList.add("eng");
224+
ObservableList<LocaleUiStringHolder> langCBObsList = FXCollections.observableArrayList();
225+
//langCBObsList.add(new LocaleUiStringHolder(new Locale("en", "US")));
225226

226227
File jarFile;
227228
try{
@@ -239,8 +240,14 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
239240
Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
240241
while (entries.hasMoreElements()) {
241242
String name = entries.nextElement().getName();
242-
if (name.startsWith("locale_"))
243-
langCBObsList.add(name.substring(7, 10));
243+
if (name.startsWith("locale_")){
244+
try{
245+
langCBObsList.add(new LocaleUiStringHolder(name));
246+
}
247+
catch (Exception e){
248+
e.printStackTrace();
249+
}
250+
}
244251
}
245252
jar.close();
246253
}
@@ -253,21 +260,37 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
253260
String[] filesList = new File(resourceURL.getFile()).list(); // Screw it. This WON'T produce NullPointerException
254261

255262
for (String jarFileName : filesList)
256-
if (jarFileName.startsWith("locale_"))
257-
langCBObsList.add(jarFileName.substring(7, 10));
263+
if (jarFileName.startsWith("locale_")){
264+
try{
265+
langCBObsList.add(new LocaleUiStringHolder(jarFileName));
266+
}
267+
catch (Exception e){
268+
e.printStackTrace();
269+
}
270+
}
258271
}
272+
langCBObsList.sort(Comparator.comparing(LocaleUiStringHolder::toString));
259273

260274
langCB.setItems(langCBObsList);
261-
if (langCBObsList.contains(AppPreferences.getInstance().getLanguage()))
262-
langCB.getSelectionModel().select(AppPreferences.getInstance().getLanguage());
263-
else
264-
langCB.getSelectionModel().select("eng");
275+
// TODO: REFACTOR THIS SHIT; INCAPSULATE AND MOVE OUT FROM HERE
276+
Locale localeFromPrefs = AppPreferences.getInstance().getLocale();
277+
boolean notExists = true;
278+
for (LocaleUiStringHolder holderItem: langCBObsList){
279+
if (holderItem.getLocale().equals(localeFromPrefs)){
280+
langCB.getSelectionModel().select(holderItem);
281+
notExists = false;
282+
break;
283+
}
284+
}
285+
if (notExists)
286+
langCB.getSelectionModel().select(0);
265287

266288
langBtn.setOnAction(e->{
267-
AppPreferences.getInstance().setLanguage(langCB.getSelectionModel().getSelectedItem());
289+
LocaleUiStringHolder localeHolder = langCB.getSelectionModel().getSelectedItem();
290+
AppPreferences.getInstance().setLocale(localeHolder.getLocaleCode());
291+
Locale newLocale = localeHolder.getLocale();
268292
ServiceWindow.getInfoNotification("",
269-
ResourceBundle.getBundle("locale", new Locale(langCB.getSelectionModel().getSelectedItem()))
270-
.getString("windowBodyRestartToApplyLang"));
293+
ResourceBundle.getBundle("locale", newLocale).getString("windowBodyRestartToApplyLang"));
271294
});
272295
// Set supported old versions
273296
glVersionChoiceBox.getItems().addAll(glSupportedVersions);

src/main/java/nsusbloader/NSLMain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232

3333
public class NSLMain extends Application {
3434

35-
public static final String appVersion = "v4.1";
35+
public static final String appVersion = "v4.2";
3636
public static boolean isCli;
3737

3838
@Override
3939
public void start(Stage primaryStage) throws Exception{
4040
FXMLLoader loader = new FXMLLoader(getClass().getResource("/NSLMain.fxml"));
4141

42-
Locale userLocale = new Locale(AppPreferences.getInstance().getLanguage()); // NOTE: user locale based on ISO3 Language codes
42+
Locale userLocale = AppPreferences.getInstance().getLocale();
4343
ResourceBundle rb = ResourceBundle.getBundle("locale", userLocale);
4444

4545
loader.setResources(rb);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2019-2020 Dmitry Isaenko
3+
4+
This file is part of NS-USBloader.
5+
6+
NS-USBloader is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
NS-USBloader is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package nsusbloader.UI;
20+
21+
import nsusbloader.cli.IncorrectSetupException;
22+
23+
import java.util.Locale;
24+
25+
public class LocaleUiStringHolder {
26+
27+
private final Locale locale;
28+
private final String localeCode;
29+
private final String languageName;
30+
31+
public LocaleUiStringHolder(Locale locale){
32+
this.locale = locale;
33+
this.localeCode = locale.toString();
34+
this.languageName = locale.getDisplayLanguage(locale) + " (" + locale + ")";
35+
}
36+
37+
public LocaleUiStringHolder(String localeFileName) throws Exception{
38+
if (localeFileName.length() < 12)
39+
throw new IncorrectSetupException("Locale filename is incorrect: "+localeFileName);
40+
String country = localeFileName.substring(7, 9);
41+
String language = localeFileName.substring(10, 12);
42+
this.locale = new Locale(country, language);
43+
this.localeCode = locale.toString();
44+
this.languageName = locale.getDisplayLanguage(locale) + " (" + locale + ")";
45+
}
46+
47+
@Override
48+
public String toString(){
49+
return languageName;
50+
}
51+
52+
public String getLocaleCode(){
53+
return localeCode;
54+
};
55+
56+
public Locale getLocale() {
57+
return locale;
58+
}
59+
}

src/main/resources/SettingsTab.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<HBox alignment="CENTER_LEFT" spacing="5.0">
2121
<children>
2222
<Label text="%tab2_Lbl_Language" />
23-
<ChoiceBox fx:id="langCB" prefWidth="100.0" />
23+
<ChoiceBox fx:id="langCB" prefWidth="180.0" />
2424
<Button fx:id="langBtn" mnemonicParsing="false" text="OK" />
2525
<VBox alignment="CENTER_RIGHT" HBox.hgrow="ALWAYS">
2626
<children>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
btn_OpenFile=Select files
2+
btn_Upload=Upload to NS
3+
tab3_Txt_EnteredAsMsg1=You have been entered as:
4+
tab3_Txt_EnteredAsMsg2=You should be root or have configured 'udev' rules for this user to avoid any issues.
5+
tab3_Txt_FilesToUploadTitle=Files to upload:
6+
tab3_Txt_GreetingsMessage=Welcome to NS-USBloader
7+
tab3_Txt_NoFolderOrFileSelected=No files selected: nothing to upload.
8+
windowBodyConfirmExit=Data transfer is in progress and closing this application will interrupt it.\nIt's the worse thing you can do now.\nInterrupt proccess and exit?
9+
windowTitleConfirmExit=No, don't do this!
10+
btn_Stop=Interrupt
11+
tab3_Txt_GreetingsMessage2=--\n\
12+
Source: https://github.com/developersu/ns-usbloader/\n\
13+
Site: https://developersu.blogspot.com/search/label/NS-USBloader\n\
14+
Dmitry Isaenko [developer.su]
15+
tab1_table_Lbl_Status=Status
16+
tab1_table_Lbl_FileName=File name
17+
tab1_table_Lbl_Size=Size
18+
tab1_table_Lbl_Upload=Upload?
19+
tab1_table_contextMenu_Btn_BtnDelete=Remove
20+
tab1_table_contextMenu_Btn_DeleteAll=Remove all
21+
tab2_Lbl_HostIP=Host IP
22+
tab1_Lbl_NSIP=NS IP:
23+
tab2_Cb_ValidateNSHostName=Always validate NS IP input.
24+
windowBodyBadIp=Are you sure that you entered NS IP address correctly?
25+
windowTitleBadIp=IP address of NS most likely incorrect
26+
tab2_Cb_ExpertMode=Expert mode (NET setup)
27+
tab2_Lbl_HostPort=port
28+
tab2_Cb_AutoDetectIp=Auto-detect IP
29+
tab2_Cb_RandSelectPort=Randomly get port
30+
tab2_Cb_DontServeRequests=Don't serve requests
31+
tab2_Lbl_DontServeRequestsDesc=If selected, this computer won't reply to NSP files requests coming from NS (over the net) and use defined host settings to tell TinFoil where should it look for files.
32+
tab2_Lbl_HostExtra=extra
33+
windowTitleErrorPort=Port set incorrectly!
34+
windowBodyErrorPort=Port can't be 0 or greater than 65535.
35+
tab2_Cb_AutoCheckForUpdates=Auto check for updates
36+
windowTitleNewVersionAval=New version available
37+
windowTitleNewVersionNOTAval=No new versions available
38+
windowTitleNewVersionUnknown=Unable to check for new versions
39+
windowBodyNewVersionUnknown=Something went wrong\nMaybe internet unavailable, or GitHub is down
40+
windowBodyNewVersionNOTAval=You're using the latest version
41+
tab2_Cb_AllowXciNszXcz=Allow XCI / NSZ / XCZ files selection for Tinfoil
42+
tab2_Lbl_AllowXciNszXczDesc=Used by applications that support XCI/NSZ/XCZ and utilizes Tinfoil transfer protocol. Don't change if not sure. Enable for Awoo Installer.
43+
tab2_Lbl_Language=Language
44+
windowBodyRestartToApplyLang=Please restart application to apply changes.
45+
btn_OpenSplitFile=Select split NSP
46+
tab2_Lbl_ApplicationSettings=Main settings
47+
tabSplMrg_Lbl_SplitNMergeTitle=Split & merge files tool
48+
tabSplMrg_RadioBtn_Split=Split
49+
tabSplMrg_RadioBtn_Merge=Merge
50+
tabSplMrg_Txt_File=File:
51+
tabSplMrg_Txt_Folder=Split file (folder):
52+
tabSplMrg_Btn_SelectFile=Select File
53+
tabSplMrg_Btn_SelectFolder=Select Folder
54+
tabSplMrg_Lbl_SaveToLocation=Save to:
55+
tabSplMrg_Btn_ChangeSaveToLocation=Change
56+
tabSplMrg_Btn_Convert=Convert
57+
windowTitleError=Error
58+
windowBodyPleaseFinishTransfersFirst=Unable to split/merge files when application USB/Network process active. Please interrupt active transfers first.
59+
done_txt=Done!
60+
failure_txt=Failed
61+
btn_Select=Select
62+
btn_InjectPayloader=Inject payload
63+
tabNXDT_Btn_Start=Start!
64+
tab2_Btn_InstallDrivers=Download and install drivers
65+
windowTitleDownloadDrivers=Download and install drivers
66+
windowBodyDownloadDrivers=Downloading drivers (libusbK v3.0.7.0)...
67+
btn_Cancel=Cancel
68+
btn_Close=Close
69+
tab2_Cb_GlVersion=GoldLeaf version
70+
tab2_Cb_GLshowNspOnly=Show only *.nsp in GoldLeaf.
71+
windowBodyPleaseStopOtherProcessFirst=Please stop other active process before continuing.

0 commit comments

Comments
 (0)