Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/main/java/com/codedead/opal/controller/LanguageController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.codedead.opal.controller;

import static com.codedead.opal.utils.SharedVariables.DEFAULT_LOCALE;

public final class LanguageController {

/**
* Initialize a new LanguageController
*/
private LanguageController() {
// Default constructor
}

/**
* Get the language index from the locale
*
* @param locale The locale
* @return The language index
*/
public static int getLanguageIndexFromLocale(final String locale) {
return switch (locale.toLowerCase()) {
case "de-de" -> 1;
case "es-es" -> 2;
case "fr-fr" -> 3;
case "jp-jp" -> 4;
case "nl-nl" -> 5;
case "ru-ru" -> 6;
case "tr-tr" -> 7;
case "zh-cn" -> 8;
default -> 0;
};
}

/**
* Get the locale from the language index
*
* @param index The language index
* @return The locale
*/
public static String getLocaleFromLanguageIndex(final int index) {
return switch (index) {
case 1 -> "de-DE";
case 2 -> "es-ES";
case 3 -> "fr-FR";
case 4 -> "jp-JP";
case 5 -> "nl-NL";
case 6 -> "ru-RU";
case 7 -> "tr-TR";
case 8 -> "zh-CN";
default -> DEFAULT_LOCALE;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ public void run() {
*/
@FXML
private void initialize() {
mniTimerEnabled.setOnAction(e ->
{
mniTimerEnabled.setOnAction(e -> {
if (mniTimerEnabled.isSelected()) {
final Properties properties = settingsController.getProperties();
final long timerDelay = Long.parseLong(properties.getProperty("timerDelay", "3600000"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import atlantafx.base.theme.*;
import com.codedead.opal.domain.NumberTextField;
import com.codedead.opal.domain.OSType;
import com.codedead.opal.domain.OsCheck;
import com.codedead.opal.utils.FxUtils;
import com.codedead.opal.utils.SharedVariables;
import javafx.application.Application;
Expand All @@ -21,6 +23,7 @@

import java.io.IOException;
import java.util.Locale;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -76,6 +79,10 @@ private void initialize() {
cboTheme.getSelectionModel()
.selectedItemProperty()
.addListener((options, oldValue, newValue) -> ThemeController.setTheme(cboTheme.getValue()));

if (Objects.requireNonNull(OsCheck.getOperatingSystemType()) == OSType.OTHER) {
chbTimerComputerShutdown.setDisable(true);
}
}

/**
Expand Down Expand Up @@ -137,16 +144,7 @@ private void loadSettings() {
timerDelay = 1;
}

switch (settingsController.getProperties().getProperty("locale", DEFAULT_LOCALE).toLowerCase()) {
case "de-de" -> cboLanguage.getSelectionModel().select(1);
case "es-es" -> cboLanguage.getSelectionModel().select(2);
case "fr-fr" -> cboLanguage.getSelectionModel().select(3);
case "jp-jp" -> cboLanguage.getSelectionModel().select(4);
case "nl-nl" -> cboLanguage.getSelectionModel().select(5);
case "ru-ru" -> cboLanguage.getSelectionModel().select(6);
case "tr-tr" -> cboLanguage.getSelectionModel().select(7);
default -> cboLanguage.getSelectionModel().select(0);
}
cboLanguage.getSelectionModel().select(LanguageController.getLanguageIndexFromLocale(settingsController.getProperties().getProperty("locale", DEFAULT_LOCALE)));

switch (settingsController.getProperties().getProperty("loglevel", "INFO").toUpperCase()) {
case "OFF" -> cboLogLevel.getSelectionModel().select(0);
Expand Down Expand Up @@ -232,16 +230,7 @@ private void saveSettingsAction() {

showAlertIfLanguageMismatch(settingsController.getProperties().getProperty("locale", DEFAULT_LOCALE));

switch (cboLanguage.getSelectionModel().getSelectedIndex()) {
case 1 -> settingsController.getProperties().setProperty("locale", "de-DE");
case 2 -> settingsController.getProperties().setProperty("locale", "es-es");
case 3 -> settingsController.getProperties().setProperty("locale", "fr-FR");
case 4 -> settingsController.getProperties().setProperty("locale", "jp-JP");
case 5 -> settingsController.getProperties().setProperty("locale", "nl-NL");
case 6 -> settingsController.getProperties().setProperty("locale", "ru-RU");
case 7 -> settingsController.getProperties().setProperty("locale", "tr-TR");
default -> settingsController.getProperties().setProperty("locale", DEFAULT_LOCALE);
}
settingsController.getProperties().setProperty("locale", LanguageController.getLocaleFromLanguageIndex(cboLanguage.getSelectionModel().getSelectedIndex()));

settingsController.getProperties().setProperty("theme", cboTheme.getSelectionModel().getSelectedItem());
settingsController.getProperties().setProperty("loglevel", cboLogLevel.getValue());
Expand Down Expand Up @@ -295,16 +284,7 @@ private void saveSettingsAction() {
* @param languageToMatch The language that needs to be matched to the combobox
*/
private void showAlertIfLanguageMismatch(final String languageToMatch) {
final String newLanguage = switch (cboLanguage.getSelectionModel().getSelectedIndex()) {
case 1 -> "de-DE";
case 2 -> "es-es";
case 3 -> "fr-FR";
case 4 -> "jp-JP";
case 5 -> "nl-NL";
case 6 -> "ru-RU";
case 7 -> "tr-TR";
default -> DEFAULT_LOCALE;
};
final String newLanguage = LanguageController.getLocaleFromLanguageIndex(cboLanguage.getSelectionModel().getSelectedIndex());

if (!languageToMatch.equals(newLanguage)) {
FxUtils.showInformationAlert(translationBundle.getString("RestartRequired"), getClass().getResourceAsStream(SharedVariables.ICON_URL));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/codedead/opal/domain/SoundPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ private void initializeMediaPlayer(final String value) throws URISyntaxException
disposeMediaPlayer();

mediaPlayer = new MediaPlayer(new Media(Objects.requireNonNull(getClass().getResource(value)).toURI().toString()));
mediaPlayer.currentTimeProperty().addListener((observableValue, oldDuration, newDuration) -> {
// Quality of life improvement to reduce audio lag when restarting the media
if (mediaPlayer != null && newDuration.toSeconds() >= mediaPlayer.getMedia().getDuration().toSeconds() - 0.5) {
mediaPlayer.seek(Duration.ZERO);
}
});
mediaPlayer.setOnEndOfMedia(() -> {
if (mediaPlayer != null) {
mediaPlayer.seek(Duration.ZERO);
Expand Down
96 changes: 96 additions & 0 deletions src/main/resources/translations/OpalApplication_zh_CN.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
About=关于
AboutText=Opal 由 DeadLine 创建\n\n音频:ZapSplat.com\n图像:Remix Icon\n主题:AtlantaFX\n版本:1.1.0\n\n版权所有 © 2023 CodeDead
AboutWindowError=无法打开“关于”窗口!
AboutWindowTitle=Opal - 关于
AutoUpdate=自动检查更新
Birds=鸟类
Chatter=喋喋不休
CheckForUpdates=检查更新
Close=关闭
ConfirmReset=您确定要重置所有设置吗?
Donate=捐
Exit=出口
File=_文件
FileExecutionError=无法打开文件!
Fireplace=壁炉
General=一般的
Help=帮助
HelpFileError=无法打开帮助文件!
HelpMenu=_帮助
Homepage=主页
Language=语言
License=执照
LicenseFileError=无法打开许可证文件!
LogLevel=日志级别
MainWindowTitle=Opal
Nature=自然
NewUpdateAvailable=版本 {v} 现已推出。 您想下载此更新吗?
NoUpdateAvailable=没有可用更新!
Office=办公室
OpenSoundPreset=打开声音预设
OpenSoundPresetError=无法打开声音预设!
Phone=电话
Rain=雨
Reset=重置
ResetSettingsError=无法重置所有设置!
RestartRequired=需要重新启动才能更改语言!
Save=节省
SaveSettingsError=无法保存设置!
SaveSoundPreset=保存声音设置
SaveSoundPresetError=无法保存声音设置!
Settings=设置
SettingsWindowError=无法打开设置窗口!
SettingsWindowTitle=Opal - 设置
Thunder=雷
Tools=_工具
Traffic=交通
Typing=打字
UpdateError=无法检查更新!
WebsiteError=无法打开网站!
Wind=风
River=河
Clock=钟
Static=静止的
Other=其他
Timer=计时器
Enabled=启用
Delay=延迟
Seconds=第二次
Minutes=分钟
Hours=小时
TimerDelayTooSmall=定时器延迟不能小于1!
Fantasy=幻想
Fan=扇子
TimerApplicationShutdown=退出应用程序
Cave=洞穴
Frogs=青蛙
Zen=禅
Coffee=咖啡
Zoo=动物园
Audiences=观众
NetworkingEvent=社交活动
TribalFestival=部落节日
RugbyFootball=橄榄球
Sleepy=困
DrumTribalFestival=鼓部落节
Gong=锣
MediaButtons=媒体按钮
DragDrop=拖放文件
Theme=主题
Space=空间
Restaurant=餐厅
Cancel=取消
Display=展示
TrayIcon=任务栏图标
TrayIconError=无法创建托盘图标!
Ocean=海洋
Train=火车
WhiteNoise=白噪声
RadioFrequencyStatic=射频静电
PinkNoise=粉红噪声
BrownNoise=布朗噪声
TimerComputerShutdown=关闭电脑
AudioBalance=音频平衡
Advanced=先进的
Seagulls=海鸥
Belltower=钟楼
16 changes: 8 additions & 8 deletions src/main/resources/windows/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<?import javafx.scene.image.Image?>

<GridPane
prefHeight="370"
prefWidth="560"
prefHeight="350"
prefWidth="550"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.codedead.opal.controller.MainWindowController"
onDragOver="#onDragOver"
Expand Down Expand Up @@ -86,7 +86,7 @@
<Image url="@../images/timer.png"/>
</ImageView>
</graphic>
<CheckMenuItem fx:id="mniTimerEnabled" text="%Enabled"/>
<CheckMenuItem fx:id="mniTimerEnabled" text="%Enabled" accelerator="Shortcut+T"/>
</Menu>
</Menu>
<Menu text="%HelpMenu">
Expand Down Expand Up @@ -166,7 +166,7 @@

<Label GridPane.rowIndex="0" GridPane.columnIndex="1" text="%Nature">
<font>
<Font name="System Bold" size="16"/>
<Font name="System Bold" size="15"/>
</font>
<GridPane.margin>
<Insets left="5" right="5" top="10"/>
Expand Down Expand Up @@ -235,7 +235,7 @@

<Label GridPane.rowIndex="3" GridPane.columnIndex="1" text="%Office">
<font>
<Font name="System Bold" size="16"/>
<Font name="System Bold" size="15"/>
</font>
<GridPane.margin>
<Insets left="5" right="5" top="10"/>
Expand Down Expand Up @@ -288,7 +288,7 @@

<Label GridPane.rowIndex="6" GridPane.columnIndex="1" text="%Audiences">
<font>
<Font name="System Bold" size="16"/>
<Font name="System Bold" size="15"/>
</font>
<GridPane.margin>
<Insets left="5" right="5" top="10"/>
Expand Down Expand Up @@ -333,7 +333,7 @@

<Label GridPane.rowIndex="9" GridPane.columnIndex="1" text="%RadioFrequencyStatic">
<font>
<Font name="System Bold" size="16"/>
<Font name="System Bold" size="15"/>
</font>
<GridPane.margin>
<Insets left="5" right="5" top="10"/>
Expand Down Expand Up @@ -377,7 +377,7 @@

<Label GridPane.rowIndex="12" GridPane.columnIndex="1" text="%Other">
<font>
<Font name="System Bold" size="16"/>
<Font name="System Bold" size="15"/>
</font>
<GridPane.margin>
<Insets left="5" right="5" top="10"/>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/windows/SettingsWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<String fx:value="Nederlands"/>
<String fx:value="Русский"/>
<String fx:value="Türkçe"/>
<String fx:value="中国人"/>
</FXCollections>
</items>
</ComboBox>
Expand Down