[gbrainy/gbrainy-17x] New TranslationWeb service



commit ec89013dae622c9dc58dfb67f5cc7169eb84a0e7
Author: Jordi Mas <jmas softcatala org>
Date:   Sun Jan 30 23:57:30 2011 +0100

    New TranslationWeb service

 src/Clients/WebForms/TranslationsWeb.cs |   73 +++++++++++++++++++++++++++++++
 src/Core/Services/ServiceLocator.cs     |    3 +-
 2 files changed, 74 insertions(+), 2 deletions(-)
---
diff --git a/src/Clients/WebForms/TranslationsWeb.cs b/src/Clients/WebForms/TranslationsWeb.cs
new file mode 100644
index 0000000..33df792
--- /dev/null
+++ b/src/Clients/WebForms/TranslationsWeb.cs
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 Jordi Mas i Hernàndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using Mono.Unix;
+
+using gbrainy.Core.Services;
+
+namespace gbrainy.Clients.WebForms
+{
+	public class TranslationsWeb : ITranslations
+	{
+		public delegate int GetLanguageIndexFromSessionHandler ();
+		static readonly object sync = new object ();
+
+		public GetLanguageIndexFromSessionHandler GetLanguageIndexFromSession;
+
+		public void Init (string package, string localedir)
+		{
+			Catalog.Init (package, localedir);
+		}
+
+		public string GetString (string s)
+		{
+			string str;
+
+			lock (sync)
+			{
+				int index = GetLanguageIndexFromSession ();
+				SetContext (index);
+				str = Catalog.GetString (s);
+			}
+			return str;
+		}
+
+		public string GetPluralString (string s, string p, int n)
+		{
+			string str;
+
+			lock (sync)
+			{
+				int index = GetLanguageIndexFromSession ();
+				SetContext (index);
+				str = Catalog.GetPluralString (s, p, n);
+			}
+			return str;
+		}
+
+		void SetContext (int index)
+		{
+			string langcode = LanguageSupport.GetFromIndex (index).LangCode;
+			Environment.SetEnvironmentVariable ("LANGUAGE", langcode);
+			Init ("gbrainy", Defines.LOCALE_DIR);
+		}
+	}
+}
+
diff --git a/src/Core/Services/ServiceLocator.cs b/src/Core/Services/ServiceLocator.cs
index 66642b5..5f3a339 100644
--- a/src/Core/Services/ServiceLocator.cs
+++ b/src/Core/Services/ServiceLocator.cs
@@ -19,7 +19,6 @@
 
 using System;
 using System.Collections.Generic;
-using SL = gbrainy.Core.Services.ServiceLocator;
 
 namespace gbrainy.Core.Services
 {
@@ -27,7 +26,7 @@ namespace gbrainy.Core.Services
 	{
 		Dictionary <Type, object> services;
 		static ServiceLocator instance = new ServiceLocator ();
-		static readonly object  sync = new object ();
+		static readonly object sync = new object ();
 
 		public ServiceLocator ()
 		{



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]