[tasque/transition: 134/213] Update translation compilation settings



commit ad0bb510765f6d93dcd088d5f2d3df6e4d851545
Author: Antonius Riha <antoniusriha gmail com>
Date:   Fri Aug 17 22:25:15 2012 +0200

    Update translation compilation settings
    
    * CompileTranslations.cs: MSBuild task to compile translations using
    msgfmt.
    * DeleteCompiledTranslations.cs: MSBuild task to clean the translation
    compilation output.
    * .gitignore: ignore translation compilation output in vcs
    
    * translation.mdproj:
    This proj file is now origanized in two parts. The above 56 lines are for the
    integration in MD. Everything below is part of the MSBuild build
    instructions.
    The project outputs to $prefix/share/locale which is by default
    build/out/share/locale. It uses to MSBuild tasks (described above) to
    manage translation compilation. The respective build targets, the tasks
    belong to, are "Build" and "Clean". The "Rebuild" target is a superposition
    of "Clean" and "Build".
    
    * libtasque.csproj: For an unkonwn reason a line in Options.cs is shown as
    being marked for translation, though it's really not. Exclude it therefore.

 .gitignore                          |    1 +
 build/CompileTranslations.cs        |  122 +++++++++++++++++++++++++++++++++++
 build/DeleteCompiledTranslations.cs |   70 ++++++++++++++++++++
 build/build.csproj                  |    2 +
 po/translation.mdproj               |   54 +++++++++++++++-
 src/libtasque/libtasque.csproj      |    1 +
 6 files changed, 248 insertions(+), 2 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 2423d2c..743679a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,7 @@ bin/
 *.dll
 *.pdb
 *.mdb
+*.mo
 
 # include binary dependencies
 !/src/tasque/lib/*
diff --git a/build/CompileTranslations.cs b/build/CompileTranslations.cs
new file mode 100644
index 0000000..fdd3831
--- /dev/null
+++ b/build/CompileTranslations.cs
@@ -0,0 +1,122 @@
+// 
+// Translate.cs
+//  
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+// 
+// Copyright (c) 2012 Antonius Riha
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Diagnostics;
+using System.IO;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Tasque.Build
+{
+	public class CompileTranslations : Task
+	{
+		public CompileTranslations ()
+		{
+			msgfmt = "msgfmt";
+			if (Environment.OSVersion.Platform != PlatformID.Unix) {
+				var programFiles32 =
+					Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86);
+				if (Directory.Exists (programFiles32))
+					msgfmt = programFiles32 + "\\GnuWin32\\bin\\msgfmt.exe";
+			}
+		}
+		
+		[Required]
+		public ITaskItem GettextCatalogName { get; set; }
+		
+		// Not sure what that is for
+		public ITaskItem GettextCatalogFile { get; set; }
+		
+		[Required]
+		public ITaskItem OutputPath { get; set; }
+		
+		[Required]
+		public ITaskItem [] TranslationSource { get; set; }
+		
+		public override bool Execute ()
+		{
+			var catalogName = GettextCatalogName.ItemSpec;
+			if (string.IsNullOrWhiteSpace (catalogName)) {
+				Log.LogError ("GettextCatalogName is invalid.");
+				return false;
+			}
+			
+			var catalogFile = GettextCatalogFile != null ? GettextCatalogFile.ItemSpec : "";
+			if (string.IsNullOrWhiteSpace (catalogFile))
+				catalogFile = "messages.po";
+			
+			var outputPath = OutputPath.ItemSpec ?? string.Empty;
+			
+			try {
+				foreach (var item in TranslationSource) {
+					var itemName = Path.GetFileNameWithoutExtension (item.ItemSpec);
+					var dirPath = Path.Combine (outputPath, itemName, "LC_MESSAGES");
+					var path = Path.Combine (dirPath, catalogName + ".mo");
+					
+					if (!Directory.Exists (dirPath))
+						Directory.CreateDirectory (dirPath);
+					
+					if (!ExecuteProcess (msgfmt, item.ItemSpec + " -o " + path))
+						return false;
+				}
+			} catch (Exception ex) {
+				Log.LogErrorFromException (ex, true);
+				return false;
+			}
+			return true;
+		}
+		
+		bool ExecuteProcess (string command, string args)
+		{
+			var startInfo = new ProcessStartInfo (command, args);
+			startInfo.UseShellExecute = false;
+			startInfo.RedirectStandardError = true;
+			startInfo.RedirectStandardOutput = true;
+			startInfo.CreateNoWindow = true;
+			
+			var p = new Process ();
+			p.StartInfo = startInfo;
+			p.OutputDataReceived += (sender, e) => {
+				if (e.Data != null)
+					Log.LogMessage (e.Data);
+			};
+			p.ErrorDataReceived += (sender, e) => {
+				if (e.Data != null)
+					Log.LogError (e.Data);
+			};
+			p.Start ();
+			p.BeginOutputReadLine ();
+			p.BeginErrorReadLine ();
+				
+			p.WaitForExit (20000);
+			if (p.ExitCode != 0)
+				return false;
+			return true;
+		}
+		
+		string msgfmt;
+	}
+}
diff --git a/build/DeleteCompiledTranslations.cs b/build/DeleteCompiledTranslations.cs
new file mode 100644
index 0000000..645e729
--- /dev/null
+++ b/build/DeleteCompiledTranslations.cs
@@ -0,0 +1,70 @@
+// 
+// DeleteCompiledTranslations.cs
+//  
+// Author:
+//       Antonius Riha <antoniusriha gmail com>
+// 
+// Copyright (c) 2012 Antonius Riha
+// 
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+// 
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.IO;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Tasque.Build
+{
+	public class DeleteCompiledTranslations : Task
+	{
+		[Required]
+		public ITaskItem GettextCatalogName { get; set; }
+		
+		[Required]
+		public ITaskItem OutputPath { get; set; }
+		
+		[Required]
+		public ITaskItem [] TranslationSource { get; set; }
+		
+		public override bool Execute ()
+		{
+			var catalogName = GettextCatalogName.ItemSpec;
+			if (string.IsNullOrWhiteSpace (catalogName)) {
+				Log.LogError ("GettextCatalogName is invalid.");
+				return false;
+			}
+			
+			var outputPath = OutputPath.ItemSpec ?? string.Empty;
+			
+			try {
+				foreach (var item in TranslationSource) {
+					var itemName = Path.GetFileNameWithoutExtension (item.ItemSpec);
+					var dirPath = Path.Combine (outputPath, itemName, "LC_MESSAGES");
+					var path = Path.Combine (dirPath, catalogName + ".mo");
+					
+					if (File.Exists (path))
+					    File.Delete (path);
+				}
+			} catch (Exception ex) {
+				Log.LogErrorFromException (ex, true);
+				return false;
+			}
+			return true;
+		}
+	}
+}
diff --git a/build/build.csproj b/build/build.csproj
index 3ed870f..c9ae10b 100644
--- a/build/build.csproj
+++ b/build/build.csproj
@@ -98,6 +98,8 @@
   <ItemGroup>
     <Compile Include="SetDataAtBuildTime.cs" />
     <Compile Include="LoadGitSubmodules.cs" />
+    <Compile Include="CompileTranslations.cs" />
+    <Compile Include="DeleteCompiledTranslations.cs" />
     <Compile Include="BuildBinScript.cs" />
     <Compile Include="CheckPrefix.cs" />
   </ItemGroup>
diff --git a/po/translation.mdproj b/po/translation.mdproj
index 48c0926..be7a51a 100644
--- a/po/translation.mdproj
+++ b/po/translation.mdproj
@@ -10,7 +10,6 @@
     <relPath>locale</relPath>
     <outputType>RelativeToOutput</outputType>
     <packageName>tasque</packageName>
-    <ReleaseVersion>0.1.10</ReleaseVersion>
     <translations>
       <translations>
         <Translation isoCode="ca" />
@@ -54,5 +53,56 @@
       </projectInformations>
     </projectInformations>
   </PropertyGroup>
-  <Target Name="Build" />
+  <!--
+  Everything above is for the MD translation project serializer, and isn't really valid MSBuild.
+  The real MSBuild project is below. Need to update MD to serialize this instead.
+  -->
+  <PropertyGroup>
+    <Prefix Condition=" '$(Prefix)' == '' ">..\build\out\</Prefix>
+    <OutputPath>$(Prefix)\share\locale</OutputPath>
+    <ReleaseVersion>0.1.10</ReleaseVersion>
+  </PropertyGroup>
+  <UsingTask AssemblyFile="..\build\bin\Tasque.Build.dll" TaskName="Tasque.Build.CompileTranslations" />
+  <UsingTask AssemblyFile="..\build\bin\Tasque.Build.dll" TaskName="Tasque.Build.DeleteCompiledTranslations" />
+  <ItemGroup>
+    <GettextTranslation Include="ca.po" />
+    <GettextTranslation Include="ca valencia po" />
+    <GettextTranslation Include="cs.po" />
+    <GettextTranslation Include="da.po" />
+    <GettextTranslation Include="de.po" />
+    <GettextTranslation Include="el.po" />
+    <GettextTranslation Include="en_GB.po" />
+    <GettextTranslation Include="eo.po" />
+    <GettextTranslation Include="es.po" />
+    <GettextTranslation Include="et.po" />
+    <GettextTranslation Include="fi.po" />
+    <GettextTranslation Include="fr.po" />
+    <GettextTranslation Include="gl.po" />
+    <GettextTranslation Include="id.po" />
+    <GettextTranslation Include="it.po" />
+    <GettextTranslation Include="ja.po" />
+    <GettextTranslation Include="nb.po" />
+    <GettextTranslation Include="nds.po" />
+    <GettextTranslation Include="nl.po" />
+    <GettextTranslation Include="ru.po" />
+    <GettextTranslation Include="pl.po" />
+    <GettextTranslation Include="pt.po" />
+    <GettextTranslation Include="pt_BR.po" />
+    <GettextTranslation Include="ro.po" />
+    <GettextTranslation Include="sl.po" />
+    <GettextTranslation Include="sr.po" />
+    <GettextTranslation Include="sr latin po" />
+    <GettextTranslation Include="sv.po" />
+    <GettextTranslation Include="th.po" />
+    <GettextTranslation Include="tr.po" />
+    <GettextTranslation Include="zh_CN.po" />
+    <GettextTranslation Include="zh_TW.po" />
+  </ItemGroup>
+  <Target Name="Build">
+    <CompileTranslations GettextCatalogName="tasque" OutputPath="$(OutputPath)" TranslationSource="@(GettextTranslation)" />
+  </Target>
+  <Target Name="Clean">
+    <DeleteCompiledTranslations GettextCatalogName="tasque" OutputPath="$(OutputPath)" TranslationSource="@(GettextTranslation)" />
+  </Target>
+  <Target Name="Rebuild" DependsOnTargets="Clean;Build" />
 </Project>
diff --git a/src/libtasque/libtasque.csproj b/src/libtasque/libtasque.csproj
index c698070..f45fed8 100644
--- a/src/libtasque/libtasque.csproj
+++ b/src/libtasque/libtasque.csproj
@@ -65,6 +65,7 @@
     <Compile Include="ReadOnlySortedNotifyCollection.cs" />
     <Compile Include="..\Options.cs">
       <Link>Options.cs</Link>
+      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
     </Compile>
     <Compile Include="Preferences.cs" />
     <Compile Include="TaskGroupModel.cs" />



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