-
-
Notifications
You must be signed in to change notification settings - Fork 5
language stuff #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
t0stiman
wants to merge
18
commits into
Insprill:master
Choose a base branch
from
t0stiman:languagestuff
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
language stuff #123
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a5572d8
fix "Failed to find locale language" warning
t0stiman 0960a6b
easier debug logging
t0stiman 1d49bc1
Add more languages
t0stiman d7cf1f7
ignore empty lines in locale.csv
t0stiman 1c46d03
add ability to translate station names
t0stiman 7091c93
get rid of annoying debug log
t0stiman 8a952d4
Merge branch 'master' of github.com:Insprill/dv-mapify into languages…
t0stiman 60b4702
improved a Dutch translation
t0stiman 2f52b96
Merge branch 'build99.4' of github.com:Insprill/dv-mapify into langua…
t0stiman 9f39c41
use the old style constructor
t0stiman 125e726
Merge branch 'build99.4' of github.com:Insprill/dv-mapify into langua…
t0stiman 92335fe
Merge branch 'master' of github.com:Insprill/dv-mapify into languages…
t0stiman cdb5f0c
use languagehelper
t0stiman 6981a61
delete obsolete CSVParser
t0stiman 915df71
hide in editor
t0stiman d920834
remove LangHelper dependency from MapifyEditor
t0stiman c8dfd1c
cast language enum
t0stiman 2fd70d7
change translator key
t0stiman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,74 +1,48 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using System.IO; | ||
| using I2.Loc; | ||
| using Mapify.Utils; | ||
| using DVLangHelper.Data; | ||
| using DVLangHelper.Runtime; | ||
| using UnityModManagerNet; | ||
|
|
||
| namespace Mapify | ||
| { | ||
| public static class Locale | ||
| { | ||
| private const string DEFAULT_LANGUAGE = "English"; | ||
| private const string MISSING_TRANSLATION = "[ MISSING TRANSLATION ]"; | ||
| public const string PREFIX = "mapify/"; | ||
| public const string STATION_PREFIX = PREFIX + "station/"; | ||
| public const string SESSION__MAP_SELECTOR = PREFIX + "session/map_selector"; | ||
| public const string LAUNCHER__SESSION_MAP = PREFIX + "launcher/session_map"; | ||
| public const string LAUNCHER__SESSION_MAP_NOT_INSTALLED = PREFIX + "launcher/session_map_not_installed"; | ||
| public const string LOADING__PLEASE_WAIT = PREFIX + "loading/please_wait"; | ||
| public const string LOADING__LOADING_MAP = PREFIX + "loading/loading_map"; | ||
| private static readonly char[] PREFIX_CHARS = PREFIX.ToCharArray(); | ||
| private const string LOCALE_FILE = "locale.csv"; | ||
| // copied from DV.Localization.LocalizationAPI.Sanitized | ||
| public const string MISSING_TRANSLATION = "[ MISSING TRANSLATION ]"; | ||
|
|
||
| private static bool initializeAttempted; | ||
| private static ReadOnlyDictionary<string, Dictionary<string, string>> csv; | ||
| public const string SESSION__MAP_SELECTOR = "session/map_selector"; | ||
| public const string LAUNCHER__SESSION_MAP = "launcher/session_map"; | ||
| public const string LAUNCHER__SESSION_MAP_NOT_INSTALLED = "launcher/session_map_not_installed"; | ||
| public const string LOADING__PLEASE_WAIT = "loading/please_wait"; | ||
| public const string LOADING__LOADING_MAP = "loading/loading_map"; | ||
|
|
||
| public static bool Load(string localeFilePath) | ||
| private static TranslationInjector translationsInjector; | ||
|
|
||
| public static bool Setup() | ||
| { | ||
| initializeAttempted = true; | ||
| if (!File.Exists(localeFilePath)) | ||
| return false; | ||
| csv = CSV.Parse(File.ReadAllText(localeFilePath)); | ||
| return true; | ||
| translationsInjector = new TranslationInjector(Mapify.ModEntry.Info.Id); | ||
| return Reset(); | ||
| } | ||
|
|
||
| public static string Get(string key) | ||
| public static bool Reset() | ||
| { | ||
| if (!initializeAttempted) | ||
| throw new InvalidOperationException("Not initialized"); | ||
| translationsInjector.ResetData(); | ||
| var localeFilePath = Path.Combine(Mapify.ModEntry.Path, LOCALE_FILE); | ||
|
|
||
| string locale = LocalizationManager.CurrentLanguage; | ||
|
|
||
| if (!csv.ContainsKey(locale)) | ||
| if (!File.Exists(localeFilePath)) | ||
| { | ||
| if (locale == DEFAULT_LANGUAGE) | ||
| { | ||
| Mapify.LogError($"Failed to find locale language {locale}! Something is broken, this shouldn't happen. Dumping CSV data:"); | ||
| Mapify.LogError($"\n{CSV.Dump(csv)}"); | ||
| return MISSING_TRANSLATION; | ||
| } | ||
|
|
||
| locale = DEFAULT_LANGUAGE; | ||
| Mapify.LogWarning($"Failed to find locale language {locale}"); | ||
| } | ||
|
|
||
| Dictionary<string, string> localeDict = csv[locale]; | ||
|
|
||
| if (localeDict.TryGetValue(key.TrimStart(PREFIX_CHARS), out string value)) { | ||
| return value; | ||
| } | ||
|
|
||
| // If there is no translation for this station's name, don't translate it. | ||
| if (key.StartsWith(STATION_PREFIX)) { | ||
| return key.Replace(STATION_PREFIX, "");; | ||
| Mapify.LogError($"Failed to find locale file at {localeFilePath}! Please make sure it's there."); | ||
| return false; | ||
| } | ||
|
|
||
| return MISSING_TRANSLATION; | ||
| translationsInjector.AddTranslationsFromCsv(localeFilePath); | ||
| return true; | ||
| } | ||
|
|
||
| public static string Get(string key, params object[] placeholders) | ||
| public static void AddTranslation(string key, DVLanguage translationSetLanguage, string translationSetTranslation) | ||
| { | ||
| return string.Format(Get(key), placeholders); | ||
| translationsInjector.AddTranslation(key, translationSetLanguage, translationSetTranslation); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.