From 5d9a0bf216c4afb134663d259e8c77935f67c031 Mon Sep 17 00:00:00 2001 From: "Daniel S. Billing" Date: Mon, 19 Apr 2021 21:14:24 +0200 Subject: [PATCH] Added capture of missing tokens --- P3D/HelperClasses/Localization.vb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/P3D/HelperClasses/Localization.vb b/P3D/HelperClasses/Localization.vb index afa38a278..64607da0d 100644 --- a/P3D/HelperClasses/Localization.vb +++ b/P3D/HelperClasses/Localization.vb @@ -1,4 +1,5 @@ -Imports Newtonsoft.Json.Linq +Imports Newtonsoft.Json +Imports Newtonsoft.Json.Linq Public Class Localization Public Shared CurrentLanguage As String = "en" @@ -106,6 +107,16 @@ Public Class Localization Return result End If Else + Dim FullPath As String = GameController.GamePath & GameMode.DefaultLocalizationsPath + Dim LocaleFilePath As String = FullPath & "missing_tokens.json" + Dim TokensFile As JObject = JObject.Parse(System.IO.File.ReadAllText(LocaleFilePath)) + If TokensFile.ContainsKey(NewTokenName) = False Then + Logger.Debug("Localization.vb: Did not find token for: " & NewTokenName) + 'Dim nexttolastpart As String = NewTokenName.Substring(NewTokenName.LastIndexOf(".") + 1) + TokensFile.Add(NewTokenName, s) + End If + File.WriteAllText(LocaleFilePath, JsonConvert.SerializeObject(TokensFile, Newtonsoft.Json.Formatting.Indented)) + If DefaultValue = "" Then Return s Else @@ -123,7 +134,7 @@ Public Class Localization Dim AvailableLanguages As New Dictionary(Of Integer, String) Dim i As Integer = 0 - For Each TokenFile In IO.Directory.GetFiles(FullPath) + For Each TokenFile In IO.Directory.GetFiles(FullPath).Where(Function(f) Not IO.Path.GetFileName(f).Equals("missing_tokens.json")) Dim json As JObject = JObject.Parse(System.IO.File.ReadAllText(TokenFile)) Dim SelectedLanguage As String = json.SelectToken("language_name").ToString AvailableLanguages.Add(i, SelectedLanguage) @@ -138,7 +149,7 @@ Public Class Localization Dim FullPath As String = GameController.GamePath & GameMode.DefaultLocalizationsPath Dim LanguageNames As New Dictionary(Of String, String) - For Each TokenFile In IO.Directory.GetFiles(FullPath) + For Each TokenFile In IO.Directory.GetFiles(FullPath).Where(Function(f) Not IO.Path.GetFileName(f).Equals("missing_tokens.json")) Dim iso = IO.Path.GetFileName(TokenFile).Replace(".json", "") Dim json As JObject = JObject.Parse(System.IO.File.ReadAllText(TokenFile)) Dim name As String = json.SelectToken("language_name").ToString @@ -153,7 +164,7 @@ Public Class Localization Dim FullPath As String = GameController.GamePath & GameMode.DefaultLocalizationsPath Dim LanguageISOs As New Dictionary(Of String, String) - For Each TokenFile In IO.Directory.GetFiles(FullPath) + For Each TokenFile In IO.Directory.GetFiles(FullPath).Where(Function(f) Not IO.Path.GetFileName(f).Equals("missing_tokens.json")) Dim iso = IO.Path.GetFileName(TokenFile).Replace(".json", "") Dim json As JObject = JObject.Parse(System.IO.File.ReadAllText(TokenFile)) Dim name As String = json.SelectToken("language_name").ToString