Skip to content

Commit

Permalink
Fix localization issues and only prompt once about overwriting themes
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Oct 16, 2019
1 parent 65a8774 commit c3c283a
Show file tree
Hide file tree
Showing 26 changed files with 73 additions and 40 deletions.
15 changes: 13 additions & 2 deletions i18n/build_locale.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import glob
import json
import os
import subprocess
import sys
import urllib.request

LOCALE_MAPPING = {
"cs": "cs_CZ",
Expand All @@ -10,6 +11,7 @@
"es_ES": "es_ES",
"fr": "fr_FR",
"it": "it_IT",
"mk": "mk_MK",
"pl": "pl_PL",
"ro": "ro_RO",
"ru": "ru_RU",
Expand All @@ -21,7 +23,16 @@

from msgfmt import make

subprocess.run(["powershell.exe", "zanata-cli/bin/zanata-cli", "pull", "-B"])
if not os.path.isdir("po"):
os.mkdir("po")

with urllib.request.urlopen("https://translate.zanata.org/rest/project/windynamicdesktop/") as fileobj:
iteration_slug = json.load(fileobj)["iterations"][0]["id"]

for name in LOCALE_MAPPING.keys():
url_name = name.replace("_", "-")
print(f"Downloading translation for {url_name}")
urllib.request.urlretrieve(f"https://translate.zanata.org/rest/file/translation/windynamicdesktop/{iteration_slug}/{url_name}/po?docId=messages", f"po/{name}.po")

for filename in glob.glob("../src/locale/*.mo"):
os.remove(filename)
Expand Down
9 changes: 0 additions & 9 deletions i18n/zanata.xml

This file was deleted.

12 changes: 4 additions & 8 deletions src/ImportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ private void ImportNext()
this.Invoke(new Action(() =>
label1.Text = string.Format(_("Importing theme from {0}..."),
Path.GetFileName(themePath))));
ThemeResult maybeResult = ThemeManager.ImportTheme(themePath);

if (maybeResult != null)
{
maybeResult.Match(e => this.Invoke(new Action(
() => ThemeLoader.HandleError(e))),
theme => ThemeManager.importedThemes.Add(theme));
}

ThemeResult result = ThemeManager.ImportTheme(themePath);
result.Match(e => this.Invoke(new Action(() => ThemeLoader.HandleError(e))),
theme => ThemeManager.importedThemes.Add(theme));

importQueue.Dequeue();
ImportNext();
Expand Down
8 changes: 6 additions & 2 deletions src/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Localization
"Français", // French
"Eλληνικά", // Greek
"Italiano", // Italian
"Македонски", // Macedonian
"Polski", // Polish
"Română", // Romanian
"Pусский", // Russian
Expand All @@ -34,7 +35,7 @@ class Localization
};

public static string[] localeNames = new string[] { "cs_CZ", "de_DE", "en_US", "es_ES",
"fr_FR", "el_GR", "it_IT", "pl_PL", "ro_RO", "ru_RU", "tr_TR", "zh_CN" };
"fr_FR", "el_GR", "it_IT", "mk_MK", "pl_PL", "ro_RO", "ru_RU", "tr_TR", "zh_CN" };

public static string currentLocale;
private static ICatalog moCatalog = null;
Expand Down Expand Up @@ -114,6 +115,7 @@ private static void LoadLocaleFromWeb()
{
using (WebClient wc = new WebClient())
{
wc.Encoding = Encoding.UTF8;
string poText = wc.DownloadString(currentLocale);
POParser parser = new POParser();
poCatalog = parser.Parse(poText).Catalog;
Expand All @@ -134,7 +136,8 @@ public static string GetTranslation(string msg)
}
else if (poCatalog != null)
{
return poCatalog.GetTranslation(new POKey(msg));
string translated = poCatalog.GetTranslation(new POKey(msg));
return string.IsNullOrEmpty(translated) ? msg : translated;
}

return msg;
Expand All @@ -149,6 +152,7 @@ private static IEnumerable<Control> GetControls(Control form)
{
yield return grandChild;
}

yield return childControl;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static List<ToolStripItem> GetMenuItems()
});
items[0].Enabled = false;

darkModeItem = new ToolStripMenuItem(_("&Night wallpaper only mode"), null, OnDarkModeClick);
darkModeItem = new ToolStripMenuItem(_("&Night Wallpaper Only Mode"), null, OnDarkModeClick);
darkModeItem.Checked = JsonConfig.settings.darkMode;
startOnBootItem = new ToolStripMenuItem(_("&Start on Boot"), null, OnStartOnBootClick);

Expand Down Expand Up @@ -79,10 +79,10 @@ private static List<ToolStripItem> GetOptionsMenuItems()

if (BrightnessController.IsDDCSupported)
{
items.Add(new ToolStripSeparator());
items.Add(new ToolStripMenuItem(_("Set Auto Brightness"), null, OnSetAutoBrightnessItemClick));
}

items.Add(new ToolStripSeparator());
items.AddRange(SystemThemeChanger.GetMenuItems());
items.AddRange(WallpaperCompressionChanger.GetMenuItems());
items.AddRange(UpdateChecker.GetMenuItems());
Expand Down
10 changes: 10 additions & 0 deletions src/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@
<data name="locale_tr_TR" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\locale\tr_TR.mo;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="locale_mk_MK" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\locale\mk_MK.mo;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
4 changes: 2 additions & 2 deletions src/SystemThemeChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public static List<ToolStripItem> GetMenuItems()
automaticAppThemeItem.Checked = JsonConfig.settings.changeAppTheme;

return new List<ToolStripItem>() {
automaticSystemThemeItem,
automaticAppThemeItem,
new ToolStripSeparator(),
automaticSystemThemeItem,
automaticAppThemeItem
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/ThemeDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion src/ThemeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,37 @@ public ThemeDialog()

public void ImportThemes(List<string> themePaths)
{
this.Enabled = false;
List<string> duplicateThemeNames = new List<string>();

foreach (string themePath in themePaths)
{
string themeId = Path.GetFileNameWithoutExtension(themePath);
int themeIndex = ThemeManager.themeSettings.FindIndex(t => t.themeId == themeId);

if (themeIndex != -1)
{
duplicateThemeNames.Add(ThemeManager.GetThemeName(
ThemeManager.themeSettings[themeIndex]));
}
}

if (duplicateThemeNames.Count > 0)
{
DialogResult result = MessageDialog.ShowQuestion(string.Format(_("The following " +
"themes are already installed:\n\t{0}\n\nDo you want to overwrite them?"),
string.Join("\n\t", duplicateThemeNames)), _("Question"), true);

if (result != DialogResult.Yes)
{
this.Enabled = true;
return;
}
}

ImportDialog importDialog = new ImportDialog() { Owner = this };
importDialog.FormClosing += OnImportDialogClosing;
importDialog.Show();
this.Enabled = false;
importDialog.InitImport(themePaths);
}

Expand Down
11 changes: 0 additions & 11 deletions src/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ public static ThemeResult ImportTheme(string importPath)
int themeIndex = themeSettings.FindIndex(t => t.themeId == themeId);
ThemeResult result;

if (themeIndex != -1)
{
bool shouldOverwrite = ThemeLoader.PromptDialog(string.Format(_("The '{0}' " +
"theme is already installed. Do you want to overwrite it?"), themeId));

if (!shouldOverwrite)
{
return null; // TODO Update when nullable reference types are supported
}
}

if (Path.GetExtension(importPath) != ".json")
{
result = ThemeLoader.ExtractTheme(importPath, themeId);
Expand Down
1 change: 1 addition & 0 deletions src/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static List<ToolStripItem> GetMenuItems()
menuItem.Checked = !JsonConfig.settings.disableAutoUpdate;

return new List<ToolStripItem>() {
new ToolStripSeparator(),
menuItem
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/WallpaperCompressionChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static List<ToolStripItem> GetMenuItems()
compressionTweakItem.Checked = isWallpaperCompressionTweaked;

return new List<ToolStripItem>() {
compressionTweakItem,
new ToolStripSeparator()
new ToolStripSeparator(),
compressionTweakItem
};
}

Expand Down
1 change: 1 addition & 0 deletions src/WinDynamicDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
<None Include="locale\es_ES.mo" />
<None Include="locale\fr_FR.mo" />
<None Include="locale\it_IT.mo" />
<None Include="locale\mk_MK.mo" />
<None Include="locale\pl_PL.mo" />
<None Include="locale\ro_RO.mo" />
<None Include="locale\ru_RU.mo" />
Expand Down
Binary file modified src/locale/cs_CZ.mo
Binary file not shown.
Binary file modified src/locale/de_DE.mo
Binary file not shown.
Binary file modified src/locale/el_GR.mo
Binary file not shown.
Binary file modified src/locale/es_ES.mo
Binary file not shown.
Binary file modified src/locale/fr_FR.mo
Binary file not shown.
Binary file modified src/locale/it_IT.mo
Binary file not shown.
Binary file added src/locale/mk_MK.mo
Binary file not shown.
Binary file modified src/locale/pl_PL.mo
Binary file not shown.
Binary file modified src/locale/ro_RO.mo
Binary file not shown.
Binary file modified src/locale/ru_RU.mo
Binary file not shown.
Binary file modified src/locale/tr_TR.mo
Binary file not shown.
Binary file modified src/locale/zh_CN.mo
Binary file not shown.

0 comments on commit c3c283a

Please sign in to comment.