Skip to content

Commit

Permalink
Add localization
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Dec 27, 2023
1 parent 3d0d483 commit e3ad5f4
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions BeatSaberMarkupLanguage/BeatSaberMarkupLanguage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<ItemGroup>
<EmbeddedResource Include="manifest.json" />
<EmbeddedResource Include="Resources\*.apng" />
<EmbeddedResource Include="Resources\*.csv" />
<EmbeddedResource Include="Resources\*.png" />
<EmbeddedResource Include="Resources\description.md" />
<EmbeddedResource Include="Views\*.bsml" />
Expand Down
14 changes: 14 additions & 0 deletions BeatSaberMarkupLanguage/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand All @@ -7,7 +8,9 @@
using HarmonyLib;
using IPA;
using IPA.Config.Stores;
using Polyglot;
using TMPro;
using UnityEngine;
using Conf = IPA.Config.Config;
using IPALogger = IPA.Logging.Logger;

Expand Down Expand Up @@ -43,6 +46,7 @@ public void Init(Conf conf, IPALogger logger)
[OnStart]
public void OnStart()
{
AddLocalizationAsync().ContinueWith((task) => Logger.Log.Error($"Failed to add localization\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
LoadAndSetUpFontFallbacksAsync().ContinueWith((task) => Logger.Log.Error($"Failed to set up fallback fonts\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
AnimationController.instance.InitializeLoadingAnimation().ContinueWith((task) => Logger.Log.Error($"Failed to initialize loading animation\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted);
}
Expand All @@ -52,6 +56,16 @@ public void OnExit()
{
}

private async Task AddLocalizationAsync()
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BeatSaberMarkupLanguage.Resources.beat-saber-markup-language.csv"))
using (StreamReader reader = new(stream))
{
string content = await reader.ReadToEndAsync();
Localization.Instance.InputFiles.Add(new LocalizationAsset { Format = GoogleDriveDownloadFormat.CSV, TextAsset = new TextAsset(content) });
}
}

private async Task LoadAndSetUpFontFallbacksAsync()
{
await FontManager.AsyncLoadSystemFonts();
Expand Down
13 changes: 13 additions & 0 deletions BeatSaberMarkupLanguage/Resources/beat-saber-markup-language.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Polyglot,100,,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_MODS_PANE_TITLE,Title of the pane to the left of the initial main menu buttons.,Mods,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_NO_MODS,Message shown when no mods have added a button to the Mods pane.,None of your currently installed mods add any buttons to this part of the menu!,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_MOD_SETTINGS_BUTTON,Text on the Mod Settings button in the game's settings menu.,Mod Settings,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_MOD_SETTINGS_TITLE,Title of the Mod Settings page.,Mod Settings,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_MOD_SETTINGS_WELCOME,Initial message shown on the mod settings page.,"Welcome to Mod Settings! If you're wondering what this new menu is, it's a separate settings menu that mods can add to. This menu is separated from the base game's settings in order to make it less likely to break. Basically, if you're not a mod developer, then don't worry about it.",,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_MOD_SETTINGS_LOAD_ERROR,Message shown when a mod settings tab can't be loaded.,Error loading settings.,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_GAMEPLAY_SETUP_BASE_GAME_TAB,Base game tab name in the gameplay setup pane.,Base Game,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_GAMEPLAY_SETUP_MODS_TAB,Mods tab name in the gameplay setup pane.,Mods,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_GAMEPLAY_SETUP_EDIT_VISIBLE_TABS_HINT,Hover hint of the edit tab visibility (eye) button in the gameplay setup pane.,Edit Tab Visibility,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_GAMEPLAY_SETUP_LOAD_ERROR,Error message shown when the gameplay setup tab can't be loaded.,Error loading gameplay tab.,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_THUMBSTICK_SETTING_NAME,,Disable thumbstick scrolling in Mod Settings,,,,,,,,,,,,,,,,,,,,,,,,,,,
BSML_THUMBSTICK_SETTING_HINT,,Limit control to the scroll bar in mod list to the left of this page. Prevents autoscrolling if you have stick drift.,,,,,,,,,,,,,,,,,,,,,,,,,,,
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Settings/BSMLSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private async Task AddButtonToMainScreen()
{
OptionsViewController optionsViewController = BeatSaberUI.DiContainer.Resolve<OptionsViewController>();
_button = UnityEngine.Object.Instantiate(optionsViewController._settingsButton, optionsViewController.transform.Find("Wrapper"));
_button.GetComponentInChildren<LocalizedTextMeshProUGUI>().Key = "Mod Settings";
_button.GetComponentInChildren<LocalizedTextMeshProUGUI>().Key = "BSML_MOD_SETTINGS_BUTTON";
_button.onClick.RemoveAllListeners();
_button.onClick.AddListener(PresentSettings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.Settings.UI.ViewControllers;
using HMUI;
using Polyglot;
using UnityEngine;

namespace BeatSaberMarkupLanguage.Settings
Expand Down Expand Up @@ -91,7 +92,7 @@ protected override void DidActivate(bool firstActivation, bool addedToHierarchy,
{
if (firstActivation)
{
this._title = "Mod Settings";
SetTitle(Localization.Get("BSML_MOD_SETTINGS_TITLE"));
navigationController = BeatSaberUI.CreateViewController<NavigationController>();
BSMLParser.instance.Parse(Utilities.GetResourceContent(Assembly.GetExecutingAssembly(), "BeatSaberMarkupLanguage.Views.settings-buttons.bsml"), navigationController.gameObject, this);

Expand Down
6 changes: 3 additions & 3 deletions BeatSaberMarkupLanguage/Views/gameplay-setup.bsml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<bg id='root-object' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://monkeymanboy.github.io/BSML-Docs/ https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd'>
<tab-selector id='new-tab-selector' tab-tag='new-tab' anchor-pos-y='0' size-delta-y='6' size-delta-x='-20' child-expand-width='true' child-control-width='true' has-separator='false'/>
<tab id='vanilla-tab' tags='new-tab' tab-name='Vanilla' anchor-pos-y='-8'>
<tab id='vanilla-tab' tags='new-tab' tab-name-key='BSML_GAMEPLAY_SETUP_BASE_GAME_TAB' anchor-pos-y='-8'>
<macro.reparent transforms='vanilla-items'/>
</tab>
<tab id='mods-tab' tags='new-tab' tab-name='Mods'>
<tab id='mods-tab' tags='new-tab' tab-name-key='BSML_GAMEPLAY_SETUP_MODS_TAB'>
<horizontal child-expand-width='false' pref-height='6' anchor-pos-y='28' size-delta-x='-16'>
<page-button direction='Left' pref-width='6' pref-height='6' tags='left-button'/>
<tab-selector tab-tag='mod-tab' child-expand-width='true' child-control-width='true' has-separator='false' page-count='3' left-button-tag='left-button' right-button-tag='right-button'/>
<page-button direction='Right' pref-width='6' pref-height='6' tags='right-button'/>
</horizontal>
<clickable-text text='👁' hover-hint='Edit Tab Visibility' on-click='show-modal' anchor-pos-x='97' anchor-pos-y='28' />
<clickable-text text='👁' hover-hint-key='BSML_GAMEPLAY_SETUP_EDIT_VISIBLE_TABS_HINT' on-click='show-modal' anchor-pos-x='97' anchor-pos-y='28' />
<macro.for-each items='mod-menus' pass-back-tags='true'>
<tab tags='mod-tab' tab-name='~tab-name' id='root-tab' anchor-max-y='0.75'/>
</macro.for-each>
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Views/gameplay-tab-error.bsml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<bg xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://monkeymanboy.github.io/BSML-Docs/ https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd'>
<modifier-container pref-width='65'>
<vertical>
<text text='Error loading gameplay tab.' />
<text text-key='BSML_GAMEPLAY_SETUP_LOAD_ERROR' />
</vertical>
</modifier-container>
</bg>
4 changes: 2 additions & 2 deletions BeatSaberMarkupLanguage/Views/main-left-screen.bsml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<bg xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://monkeymanboy.github.io/BSML-Docs/ https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd' id='root-object' size-delta-x='-50' anchor-pos-x='-10'>
<vertical child-control-height='false'>
<horizontal bg='panel-top' pad-left='10' pad-right='10' horizontal-fit='PreferredSize'>
<text text='Mods' align='Center' font-size='10'></text>
<text text-key='BSML_MODS_PANE_TITLE' align='Center' font-size='10'></text>
</horizontal>
<macro.if value='any-buttons'>
<horizontal>
Expand All @@ -16,7 +16,7 @@
</macro.if>
</vertical>
<macro.if value='!any-buttons'>
<text anchor-pos-y='6' size-delta-x='82' text='None of your currently installed mods add any buttons to this part of the menu!' font-align='Center' font-size='5'/>
<text anchor-pos-y='6' size-delta-x='82' text-key='BSML_NO_MODS' font-align='Center' font-size='5'/>
</macro.if>
<!--<modal show-event='show-pins' hide-event='close-modals' size-delta-x='35' size-delta-y='65' click-off-closes='true'>
<vertical>
Expand Down
4 changes: 2 additions & 2 deletions BeatSaberMarkupLanguage/Views/settings-about.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<text align="Center"
italics="true"
word-wrapping="true"
text="Welcome to Mod Settings! If you're wondering what this new menu is, it's a separate settings menu that mods can add to. This menu is separated from the base game's settings in order to make it less likely to break. Basically, if you're not a mod developer, then don't worry about it."/>
text-key="BSML_MOD_SETTINGS_WELCOME"/>
</horizontal>
<horizontal>
<text text="---" font-color="#00000000"/>
</horizontal>
<checkbox-setting value="thumbstick-value" on-change="set-thumbstick" text="Disable thumbstick scrolling in Mod Tabs" hover-hint="Limit control to scrollbars in left menu. Prevents autoscrolling if you have stick drift"/>
<checkbox-setting value="thumbstick-value" on-change="set-thumbstick" text-key="BSML_THUMBSTICK_SETTING_NAME" hover-hint-key="BSML_THUMBSTICK_SETTING_HINT"/>
</settings-container>
4 changes: 2 additions & 2 deletions BeatSaberMarkupLanguage/Views/settings-buttons.bsml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<horizontal id='bottom-buttons' horizontal-fit='PreferredSize' child-control-height='false' child-expand-height='false' child-align='MiddleCenter' anchor-min-x='0.5' anchor-max-x='0.5' anchor-min-y='0' anchor-max-y='0' size-delta-x='120' size-delta-y='10' pivot-y='0' spacing='2'>
<button on-click='cancel-click' text='cancel' pref-width='34' pref-height='10'/>
<primary-button on-click='ok-click' text='ok' pref-width='34' pref-height='10'/>
<button on-click='cancel-click' text-key='BUTTON_CANCEL' pref-width='34' pref-height='10'/>
<primary-button on-click='ok-click' text-key='BUTTON_OK' pref-width='34' pref-height='10'/>
</horizontal>
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Views/settings-error.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<horizontal preferred-width="90">
<text align="Center"
word-wrapping="true"
text="Error loading settings."/>
text-key="BSML_MOD_SETTINGS_LOAD_ERROR"/>
</horizontal>
</settings-container>
6 changes: 6 additions & 0 deletions BeatSaberMarkupLanguage/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
"project-home": "https://github.com/monkeymanboy/BeatSaberMarkupLanguage",
"project-source": "https://github.com/monkeymanboy/BeatSaberMarkupLanguage/tree/master/BeatSaberMarkupLanguage",
"donate": "https://ko-fi.com/monkeymanboy"
},
"features": {
"SiraLocalizer.LocalizedPlugin": {
"id": "beat-saber-markup-language",
"resourcePath": "BeatSaberMarkupLanguage.Resources.beat-saber-markup-language.csv"
}
}
}

0 comments on commit e3ad5f4

Please sign in to comment.