Skip to content

Portugues localisation #561

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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Languages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows;
using ModAssistant.Pages;

namespace ModAssistant
{
internal class Languages
{
public static string LoadedLanguage { get; private set; }
public static List<CultureInfo> LoadedLanguages => availableCultures.ToList();
public static bool FirstRun = true;
private static readonly string[] availableLanguageCodes = { "de", "en", "es", "fr", "it", "ko", "nb", "nl", "pl","pt", "ru", "sv", "th", "zh" };
private static IEnumerable<CultureInfo> availableCultures;

public static void LoadLanguages()
{
var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

// Get CultureInfo for any of the available translations
availableCultures = allCultures.Where(cultureInfo => availableLanguageCodes.Any(code => code.Equals(cultureInfo.Name)));

string savedLanguageCode = Properties.Settings.Default.LanguageCode;
if (!LoadLanguage(savedLanguageCode))
{
// If no language code was saved, load system language
if (!LoadLanguage(CultureInfo.CurrentUICulture.Name))
{
_ = LoadLanguage("en");
}
}

UpdateUI(LoadedLanguage);
}

public static void UpdateUI(string languageCode)
{
if (Options.Instance != null && Options.Instance.LanguageSelectComboBox != null)
{
Options.Instance.LanguageSelectComboBox.ItemsSource = availableCultures.Select(cultureInfo => cultureInfo.NativeName).ToList();
Options.Instance.LanguageSelectComboBox.SelectedIndex = LoadedLanguages.FindIndex(cultureInfo => cultureInfo.Name.Equals(languageCode));
}
}

public static ResourceDictionary LanguagesDict
{
get
{
return Application.Current.Resources.MergedDictionaries[1];
}
}

public static bool LoadLanguage(string languageCode)
{
if (string.IsNullOrEmpty(languageCode))
{
return false;
}

try
{
LanguagesDict.Source = new Uri($"Localisation/{languageCode}.xaml", UriKind.Relative);
LoadedLanguage = languageCode;
return true;
}
catch (IOException)
{
if (languageCode.Contains("-"))
{
return LoadLanguage(languageCode.Split('-').First());
}

return false;
}
}
}
}
Loading
Loading