Last active
August 29, 2015 14:11
-
-
Save aliozgur/5fb88ffff15bb1269578 to your computer and use it in GitHub Desktop.
Xamarin.Mobile : T4 template to generate resource keys from GNU PO files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
msgid "" | |
msgstr "" | |
"Project-Id-Version: MyProject\n" | |
"Report-Msgid-Bugs-To: \n" | |
"POT-Creation-Date: \n" | |
"PO-Revision-Date: \n" | |
"Last-Translator: Ali Özgür\n" | |
"Language-Team: Turkish\n" | |
"MIME-Version: 1.0\n" | |
"Content-Type: text/plain; charset=UTF-8\n" | |
"Content-Transfer-Encoding: 8bit\n" | |
"X-Generator: Poedit 1.6.9\n" | |
"Plural-Forms: nplurals=2; plural=n > 1;\n" | |
"Language: tr_TR\n" | |
# use http://converter.webtranslateit.com/ to convert to RESX | |
msgid "AppName" | |
msgstr "My locale value" | |
msgid "Placeholder_Username" | |
msgstr "My locale value" | |
msgid "Placeholder_Password" | |
msgstr "My locale value" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ template language="C#" hostspecific="true" debug="true"#> | |
<#@ assembly name="System.Core" #> | |
<#@ import namespace="System.Linq" #> | |
<#@ import namespace="System.Text" #> | |
<#@ import namespace="System.Collections.Generic" #> | |
<#@ import namespace="System.IO" #> | |
<#@ import namespace="System.Text.RegularExpressions" #> | |
<#@ import namespace="System.Diagnostics" #> | |
namespace VoltPms | |
{ | |
///<summary> | |
/// This is an auto generated file. Do not modify | |
/// Generated by POKeyGenerator.tt | |
///</summary> | |
public class K | |
{ | |
<# | |
var propNames = ParsePo(); | |
foreach(var propName in propNames) | |
{ | |
#> | |
public const string <#=propName#> = "<#=propName#>"; | |
<# | |
} | |
#> | |
} | |
} | |
<#+ | |
private List<string> ParsePo() | |
{ | |
List<string> result = new List<string>(); | |
var path = Host.ResolvePath("./Resx/AppResources.tr.po"); | |
if(String.IsNullOrWhiteSpace(path)) | |
return result; | |
return ReadMsgIdLines(path); | |
} | |
public List<string> ReadMsgIdLines(string path) | |
{ | |
List<string> result = new List<string>(); | |
Regex regex = new Regex("\\s*msgid\\s*\\\"(?<propName>\\s*.*\\s*)\\\""); | |
string line = String.Empty; | |
System.IO.StreamReader file = new System.IO.StreamReader(path); | |
while((line = file.ReadLine()) != null) | |
{ | |
var m = regex.Match(line); | |
if (m == null || !m.Success) | |
continue; | |
var propName = m.Groups["propName"]; | |
if(propName == null || String.IsNullOrWhiteSpace(propName.Value)) | |
continue; | |
result.Add(propName.Value); | |
} | |
return result; | |
} | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More about GNU PO file format can be found here https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html