From 7fc6b6831df9ec12f7d1a25ad31794395bf183b6 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 11 Oct 2014 20:54:37 +0200 Subject: [PATCH] Added localization to top-level geonames --- Site5/App_GlobalResources/GeographyNames.resx | 139 ++++++++++++++++++ Site5/Automation/Json-GeographiesTree.aspx.cs | 19 ++- .../Controls/v5/Base/ComboGeographies.ascx.cs | 7 +- Site5/Pages/v5/Admin/CreateOrganization.aspx | 91 +----------- Site5/Pages/v5/Init/Default.aspx.cs | 2 +- 5 files changed, 166 insertions(+), 92 deletions(-) create mode 100644 Site5/App_GlobalResources/GeographyNames.resx diff --git a/Site5/App_GlobalResources/GeographyNames.resx b/Site5/App_GlobalResources/GeographyNames.resx new file mode 100644 index 00000000..07d49408 --- /dev/null +++ b/Site5/App_GlobalResources/GeographyNames.resx @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Eastern Europe + (East of former Iron Curtain) + + + Europe + + + Nordics + (Finland Denmark Norway Sweden Iceland) + + + Western Europe + (West of former Iron Curtain) + + + World + Root geography + + \ No newline at end of file diff --git a/Site5/Automation/Json-GeographiesTree.aspx.cs b/Site5/Automation/Json-GeographiesTree.aspx.cs index 1ccf346f..71f8ed31 100644 --- a/Site5/Automation/Json-GeographiesTree.aspx.cs +++ b/Site5/Automation/Json-GeographiesTree.aspx.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Threading; using Swarmops.Logic.Structure; namespace Swarmops.Frontend.Automation @@ -9,6 +10,8 @@ namespace Swarmops.Frontend.Automation { protected void Page_Load(object sender, EventArgs e) { + GetAuthenticationDataAndCulture(); + Response.ContentType = "application/json"; int rootGeographyId = Geography.RootIdentity; @@ -23,7 +26,7 @@ namespace Swarmops.Frontend.Automation // Is this stuff in cache already? - string cacheKey = "Geographies-Json-" + rootGeographyId.ToString(CultureInfo.InvariantCulture); + string cacheKey = "Geographies-Json-" + rootGeographyId.ToString(CultureInfo.InvariantCulture) + "-" + Thread.CurrentThread.CurrentCulture.Name; string accountsJson = (string) Cache[cacheKey]; @@ -75,7 +78,7 @@ namespace Swarmops.Frontend.Automation foreach (Geography geography in treeMap[node]) { string element = string.Format("\"id\":{0},\"text\":\"{1}\"", geography.Identity, - JsonSanitize(geography.Name)); + JsonSanitize(TestLocalization(geography.Name))); if (treeMap.ContainsKey(geography.Identity)) { @@ -88,5 +91,17 @@ namespace Swarmops.Frontend.Automation return "[" + String.Join(",", elements.ToArray()) + "]"; } + + private string TestLocalization(string name) + { + if (name.StartsWith("[LOC]")) + { + return Resources.GeographyNames.ResourceManager.GetString(name.Substring(5)); + } + else + { + return name; + } + } } } \ No newline at end of file diff --git a/Site5/Controls/v5/Base/ComboGeographies.ascx.cs b/Site5/Controls/v5/Base/ComboGeographies.ascx.cs index 5b58c25e..4bb1eef7 100644 --- a/Site5/Controls/v5/Base/ComboGeographies.ascx.cs +++ b/Site5/Controls/v5/Base/ComboGeographies.ascx.cs @@ -20,7 +20,12 @@ namespace Swarmops.Controls.Base set { this.RootGeographyId = value.Identity; - RootGeographyName = value.Name; + RootGeographyName = value.Name; + + if (value.Name.StartsWith("[LOC]")) + { + RootGeographyName = Resources.GeographyNames.ResourceManager.GetString(value.Name.Substring(5)); + } } } } diff --git a/Site5/Pages/v5/Admin/CreateOrganization.aspx b/Site5/Pages/v5/Admin/CreateOrganization.aspx index 1dc9ed71..524c2dd1 100644 --- a/Site5/Pages/v5/Admin/CreateOrganization.aspx +++ b/Site5/Pages/v5/Admin/CreateOrganization.aspx @@ -14,93 +14,10 @@ @@ -108,12 +25,10 @@ -
- ​
- ​
-  
- "> 
+ ​
+ +  
diff --git a/Site5/Pages/v5/Init/Default.aspx.cs b/Site5/Pages/v5/Init/Default.aspx.cs index eb1227cd..8daa3f22 100644 --- a/Site5/Pages/v5/Init/Default.aspx.cs +++ b/Site5/Pages/v5/Init/Default.aspx.cs @@ -389,7 +389,7 @@ public partial class Pages_v5_Init_Default : System.Web.UI.Page // Initialize the root geography (which becomes #1 if everything works) - int rootGeographyId = SwarmDb.GetDatabaseForWriting().CreateGeography("World", 0); + int rootGeographyId = SwarmDb.GetDatabaseForWriting().CreateGeography("[LOC]World", 0); // Get the list of countries