Skip to content

Commit

Permalink
Modified the way the translation is done to use the data fetch online…
Browse files Browse the repository at this point in the history
… on warframe market. It is similar to WFCD#231

MasterIt has not been tested.
Displays are not translated.
  • Loading branch information
Corentin-Aulagnet committed Jun 30, 2022
1 parent 8260181 commit 6ff1c08
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
54 changes: 15 additions & 39 deletions WFInfo/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Data
public JObject relicData; // Contains relicData from Warframe PC Drops {<Era>: {"A1":{"vaulted": true,<rare1/uncommon[12]/common[123]>: <part>}, ...}, "Meso": ..., "Neo": ..., "Axi": ...}
public JObject equipmentData; // Contains equipmentData from Warframe PC Drops {<EQMT>: {"vaulted": true, "PARTS": {<NAME>:{"relic_name":<name>|"","count":<num>}, ...}}, ...}
public JObject nameData; // Contains relic to market name translation {<relic_name>: <market_name>}
public JObject translationData; // Contains names of parts in locale language and in english {<locale_relic_name> : <english_part_name>}

private static List<Dictionary<int, List<int>>> korean = new List<Dictionary<int, List<int>>>() {
new Dictionary<int, List<int>>() {
Expand Down Expand Up @@ -56,7 +55,6 @@ class Data
private readonly string equipmentDataPath;
private readonly string relicDataPath;
private readonly string nameDataPath;
private readonly string translationDataPath;

public string JWT; // JWT is the security key, store this as email+pw combo
private readonly WebSocket marketSocket = new WebSocket("wss://warframe.market/socket?platform=pc");
Expand All @@ -80,7 +78,6 @@ public Data(IReadOnlyApplicationSettings settings)
equipmentDataPath = applicationDirectory + @"\eqmt_data.json";
relicDataPath = applicationDirectory + @"\relic_data.json";
nameDataPath = applicationDirectory + @"\name_data.json";
translationDataPath = applicationDirectory + @"\translation_data.json";

Directory.CreateDirectory(applicationDirectory);

Expand Down Expand Up @@ -302,8 +299,6 @@ private bool LoadEqmtData(JObject allFiltered, bool force = false)
relicData = File.Exists(relicDataPath) ? JsonConvert.DeserializeObject<JObject>(File.ReadAllText(relicDataPath)) : new JObject();
if (nameData == null)
nameData = File.Exists(nameDataPath) ? JsonConvert.DeserializeObject<JObject>(File.ReadAllText(nameDataPath)) : new JObject();
if (translationData == null)
translationData = File.Exists(translationDataPath) ? JsonConvert.DeserializeObject<JObject>(File.ReadAllText(translationDataPath)) : new JObject();
// fill in equipmentData (NO OVERWRITE)
// fill in nameData
// fill in relicData
Expand All @@ -316,7 +311,6 @@ private bool LoadEqmtData(JObject allFiltered, bool force = false)
equipmentData["timestamp"] = DateTime.Now;
relicData["timestamp"] = DateTime.Now;
nameData = new JObject();
translationData = new JObject();
foreach (KeyValuePair<string, JToken> era in allFiltered["relics"].ToObject<JObject>())
{
relicData[era.Key] = new JObject();
Expand Down Expand Up @@ -362,7 +356,6 @@ private bool LoadEqmtData(JObject allFiltered, bool force = false)
{
nameData[gameName] = partName;
string localeRelicName = Translator.TranslateParName(gameName, _settings.Locale);
translationData[localeRelicName] = partName;
marketData[partName]["ducats"] = Convert.ToInt32(part.Value["ducats"].ToString(), Main.culture);
}
}
Expand All @@ -372,29 +365,13 @@ private bool LoadEqmtData(JObject allFiltered, bool force = false)
foreach (KeyValuePair<string, JToken> ignored in allFiltered["ignored_items"].ToObject<JObject>())
{
nameData[ignored.Key] = ignored.Key;
translationData[ignored.Key] = ignored.Key;
}
translationData["locale"]=_settings.Locale;
Main.AddLog("Prime Database has been downloaded");
return true;
}
Main.AddLog("Prime Database is up to date");
return false;
}
public void UpdateTranslationdb()
{
if (translationData["locale"].ToString() != _settings.Locale)
{
translationData = new JObject();
foreach (KeyValuePair<string, JToken> englishNames in nameData)
{
string localeRelicName = Translator.TranslateParName(englishNames.Key, _settings.Locale);
translationData[localeRelicName] = englishNames.Value.ToString();
}
translationData["locale"] = _settings.Locale;
SaveDatabase(translationDataPath, translationData);
}
}
private void RefreshMarketDucats()
{
//equipmentData[primeName]["parts"][partName]["ducats"]
Expand Down Expand Up @@ -498,7 +475,6 @@ public void SaveAllJSONs()
SaveDatabase(nameDataPath, nameData);
SaveDatabase(marketItemsPath, marketItems);
SaveDatabase(marketDataPath, marketData);
SaveDatabase(translationDataPath, translationData);
}

public void ForceEquipmentUpdate()
Expand Down Expand Up @@ -616,11 +592,19 @@ public int LevenshteinDistance(string s, string t)
case "ko":
// for korean
return LevenshteinDistanceKorean(s, t);
case "fr":
return LevenshteinDistanceFrench(s, t);
default:
return LevenshteinDistanceDefault(s, t);
}
}

int LevenshteinDistanceFrench(string firstWord, string secondWord)
{
firstWord = getLocaleNameData(firstWord);
firstWord = firstWord.Replace("Schéma", "").Replace("-", "").Trim();
secondWord = secondWord.Replace("Schéma", "").Trim();
return LevenshteinDistanceDefault(firstWord, secondWord);
}
public int LevenshteinDistanceDefault(string s, string t)
{
// Levenshtein Distance determines how many character changes it takes to form a known result
Expand Down Expand Up @@ -678,6 +662,10 @@ public static bool isKorean(String str)
if (0xAC00 <= c && c <= 0xD7A3) return true;
return false;
}
/*
* Returns the locale market name of s
* s is the market name in english
*/
public string getLocaleNameData(string s)
{
bool saveDatabases = false;
Expand All @@ -687,7 +675,7 @@ public string getLocaleNameData(string s)
if (marketItem.Key == "version")
continue;
string[] split = marketItem.Value.ToString().Split('|');
if (split[0] == s)
if (split[0].Replace("Blueprint", "").Trim() == s.Replace("Blueprint", "").Trim())
{
if (split.Length == 3)
{
Expand Down Expand Up @@ -874,18 +862,7 @@ public string GetPartName(string name, out int low, bool suppressLogging)
string lowest = null;
string lowest_unfiltered = null;
low = 9999;
JObject namesData;
switch (_settings.Locale)
{
case "fr":
namesData = translationData;
break;
default:
namesData = nameData;
break;
}

foreach (KeyValuePair<string, JToken> prop in namesData)
foreach (KeyValuePair<string, JToken> prop in nameData)
{
int val = LevenshteinDistance(prop.Key, name);
if (val < low)
Expand All @@ -900,7 +877,6 @@ public string GetPartName(string name, out int low, bool suppressLogging)
lowest_unfiltered = prop.Key;
}
}

if (!suppressLogging)
Main.AddLog("Found part(" + low + "): \"" + lowest_unfiltered + "\" from \"" + name + "\"");
return lowest;
Expand Down
4 changes: 3 additions & 1 deletion WFInfo/Ocr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,9 @@ private static WFtheme GetClosestTheme(Color clr, out int threshold)
/// <returns>If part name is close enough to valid to actually process</returns>
internal static bool PartNameValid (string partName)
{
if ((partName.Length < 13 && _settings.Locale == "en") || (partName.Replace(" ", "").Length < 6 && _settings.Locale == "ko")) // if part name is smaller than "Bo prime handle" skip current part
if ((partName.Length < 13 && _settings.Locale == "en")
|| (partName.Replace(" ", "").Length < 6 && _settings.Locale == "ko")
|| partName.Length < 13 && _settings.Locale == "fr") // if part name is smaller than "Bo prime handle" skip current part
//TODO: Add a min character for other locale here.
return false;
return true;
Expand Down
1 change: 0 additions & 1 deletion WFInfo/Settings/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ private void localeComboboxSelectionChanged(object sender, System.Windows.Contro
Save();

_ = OCR.updateEngineAsync();
Main.dataBase.UpdateTranslationdb();
_ = Task.Run(async () =>
{
Main.dataBase.ReloadItems();
Expand Down

0 comments on commit 6ff1c08

Please sign in to comment.