diff --git a/Program.cs b/Program.cs index 321b50c..dbc4733 100644 --- a/Program.cs +++ b/Program.cs @@ -181,7 +181,7 @@ internal static void WriteCoffeeTranslationFileFromCldrXml(XDocument cldr) string content = (node.FirstNode as XText).Value; string formattedContent = FormatStringLiteral(content); - langFileWriter.WriteLine($"{languageName}: {formattedContent}"); + langFileWriter.WriteLine($"{EscapeKeyName(languageName)}: {formattedContent}"); } string langFileContents = langFileWriter.ToString(); @@ -219,7 +219,7 @@ internal static void WriteCoffeeTranslationFileFromCldrXml(XDocument cldr) string formattedContent = FormatStringLiteral(content); - countryFileWriter.WriteLine($"{countryName}: {formattedContent}"); + countryFileWriter.WriteLine($"{EscapeKeyName(countryName)}: {formattedContent}"); } string countryFileContents = countryFileWriter.ToString(); @@ -233,6 +233,20 @@ internal static void WriteFileHeaderComment(StringWriter writer) writer.WriteLine(); } + internal static string EscapeKeyName(string keyName) + { + string result = string.Empty; + + if (char.IsDigit(keyName[0])) + { + result += "_"; + } + + result += keyName.Replace("-", "_"); + + return result; + } + internal static string FormatStringLiteral(string srcValue) { srcValue = srcValue.Replace("\\", "\\\\");