From fabf63607b159170aa748d81aba3f6a765dc83e2 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Sat, 26 Mar 2022 22:44:17 +0100 Subject: [PATCH] i18n for tosamp --- .../gdxapp4d/app/tosamp/TosAmpComponent.java | 13 ++++++++- .../gdxapp4d/app/tosamp/TosAmpDeskApp.java | 29 ++++++++++++------- .../gdxapp4d/app/tosamp/Messages.properties | 8 +++++ .../app/tosamp/Messages_hiero.properties | 8 +++++ 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages.properties create mode 100644 gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages_hiero.properties diff --git a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java index 5f6da4bc..b86c1007 100644 --- a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java +++ b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpComponent.java @@ -1,5 +1,7 @@ package love.distributedrebirth.gdxapp4d.app.tosamp; +import java.util.ResourceBundle; + import org.osgi.framework.BundleContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; @@ -10,6 +12,7 @@ import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxBootArgs; import love.distributedrebirth.gdxapp4d.tos4.service.SystemGdxLog; import love.distributedrebirth.gdxapp4d.tos4.service.SystemWarpShip; import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4DeskAppService; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4LocaleService; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppLauncher; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppMenuSection; @@ -28,15 +31,23 @@ public class TosAmpComponent { @Reference private SystemWarpShip warpShip; + @Reference + private VrGem4LocaleService localeService; + + private final static String I18N_BUNDLE = "love.distributedrebirth.gdxapp4d.app.tosamp.Messages"; private DeskAppLauncher launcher; public TosAmpComponent() { } + private ResourceBundle createBundle() { + return ResourceBundle.getBundle(I18N_BUNDLE, localeService.getTextLocale()); + } + @Activate void open(final BundleContext context) { log.debug(this, SystemGdxLog.ACTIVATE); - launcher = new DeskAppLauncher(DeskAppMenuSection.MULTIMEDIA, "TosAmp", () -> new TosAmpDeskApp(bootArgs.getFileChooser(), context, warpShip)); + launcher = new DeskAppLauncher(DeskAppMenuSection.MULTIMEDIA, "TosAmp", () -> new TosAmpDeskApp(createBundle(), bootArgs.getFileChooser(), context, warpShip)); deskAppService.installDeskApp(launcher); } diff --git a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java index 502a275c..50dba09f 100644 --- a/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java +++ b/gdxapp4d-app-tosamp/src/main/java/love/distributedrebirth/gdxapp4d/app/tosamp/TosAmpDeskApp.java @@ -1,5 +1,6 @@ package love.distributedrebirth.gdxapp4d.app.tosamp; +import java.util.ResourceBundle; import java.util.function.Consumer; import org.osgi.framework.BundleContext; @@ -25,24 +26,30 @@ import net.spookygames.gdx.nativefilechooser.NativeFileChooserConfiguration; @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer { - + + private final ResourceBundle bundle; private final MusicManager music; private final NativeFileChooser fileChooser; private NativeFileChooserConfiguration fileChooserConfig; - public TosAmpDeskApp(NativeFileChooser fileChooser, BundleContext context, SystemWarpShip warpShip) { + public TosAmpDeskApp(ResourceBundle bundle, NativeFileChooser fileChooser, BundleContext context, SystemWarpShip warpShip) { + this.bundle = bundle; this.fileChooser = fileChooser; this.music = new MusicManager(); this.music.init(context, warpShip); } + private String getTxt(String key) { + return bundle.getString(TosAmpDeskApp.class.getSimpleName()+"."+key); + } + public void create() { - getContours().setTitle("\uf001 TosAmp"); + getContours().setTitle(getTxt("title")); getContours().registrateContour(DeskAppContourSection.MAIN, this); getContours().registrateContour(DeskAppContourSection.FILE_NEW, new DeskAppRenderer() { @Override public void render() { - if (ImGui.menuItem(FontAwesomeIcons.Plus + " Add")) { + if (ImGui.menuItem(getTxt("menuAdd"))) { fileChooser.chooseFile(fileChooserConfig, NativeFileChooserCallbackAdapter.onFileChosen(v -> music.addBackgroundMusic(v))); } @@ -56,7 +63,7 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer { @Override public void render() { - ImGui.text("Current Song:"); + ImGui.text(getTxt("currentSong")); MusicSong currentSong = music.getCurrentSong(); if (currentSong != null) { ImGui.sameLine(); @@ -64,11 +71,11 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer { } ImGui.separator(); if (currentSong != null) { - if (ImGui.button("Play")) { + if (ImGui.button(getTxt("play"))) { music.play(currentSong); } } else { - ImGui.text("Play"); + ImGui.text(getTxt("actionPlay")); } ImGui.sameLine(); if (ImGui.button("<")) { @@ -79,15 +86,15 @@ public class TosAmpDeskApp extends AbstractDeskApp implements DeskAppRenderer { music.next(); } ImGui.sameLine(); - if (ImGui.button("Stop")) { + if (ImGui.button(getTxt("actionStop"))) { music.stop(); } int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV; ImGui.beginTable("playlist", 4, flags); ImGui.tableSetupColumn("#", ImGuiTableColumnFlags.NoHide); - ImGui.tableSetupColumn("Play"); - ImGui.tableSetupColumn("List"); - ImGui.tableSetupColumn("Name"); + ImGui.tableSetupColumn(getTxt("listPlay")); + ImGui.tableSetupColumn(getTxt("listName")); + ImGui.tableSetupColumn(getTxt("listSong")); ImGui.tableHeadersRow(); int i=1; for (MusicSong song:music.getMusicSongs()) { diff --git a/gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages.properties b/gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages.properties new file mode 100644 index 00000000..438e070a --- /dev/null +++ b/gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages.properties @@ -0,0 +1,8 @@ +TosAmpDeskApp.title=\uf001 TosAmp +TosAmpDeskApp.menuAdd=\uf067 Add +TosAmpDeskApp.currentSong=Current Song: +TosAmpDeskApp.actionPlay=Play +TosAmpDeskApp.actionStop=Stop +TosAmpDeskApp.listPlay=Do +TosAmpDeskApp.listName=Playlist +TosAmpDeskApp.listSong=Song \ No newline at end of file diff --git a/gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages_hiero.properties b/gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages_hiero.properties new file mode 100644 index 00000000..a7ca2698 --- /dev/null +++ b/gdxapp4d-app-tosamp/src/main/resources/love/distributedrebirth/gdxapp4d/app/tosamp/Messages_hiero.properties @@ -0,0 +1,8 @@ +TosAmpDeskApp.title=\uf001 TosAmp +TosAmpDeskApp.menuAdd=\uf067 Add +TosAmpDeskApp.currentSong=Current Song: +TosAmpDeskApp.actionPlay=Play +TosAmpDeskApp.actionStop=Stop +TosAmpDeskApp.listPlay=Do +TosAmpDeskApp.listName=Playlist +TosAmpDeskApp.listSong=Song