<commit_before>﻿using System.IO;
using System.Xml.Linq;
using ResxConverter.Core;

namespace ResxConverter.Mobile
{
    public class AndroidResxConverterOutput : IResxConverterOutput
    {
        private string _culture;
        private string _outputProjectFolder;
        private XDocument _xDocument;
        private string _finalOutPutPath;

        public AndroidResxConverterOutput(string outputProjectFolder, string culture)
        {
            _outputProjectFolder = outputProjectFolder;
            _culture = culture;

            CreateXml();
        }

        private void CreateXml()
        {
            var cultureInfo = string.IsNullOrEmpty(_culture) ? string.Empty : $"-{_culture}";

            _finalOutPutPath = Path.Combine(_outputProjectFolder, $"values{cultureInfo}", "strings.xml");
            Directory.CreateDirectory(Path.GetDirectoryName(_finalOutPutPath));

            _xDocument = new XDocument(new XElement("resources"));
        }

        public void Dispose()
        {
            _xDocument.Save(_finalOutPutPath);
        }

        public void WriteComment(string comment)
        {
            _xDocument.Root.Add(new XComment(comment));
        }

        public void WriteString(ResxString stringElement)
        {
            _xDocument.Root.Add(CreateString(stringElement));
        }

        private XElement CreateString(ResxString stringElement)
        {
            var xStringElement = new XElement("string")
            {
                Value = stringElement.Value
            };
            xStringElement.SetAttributeValue("name", stringElement.Key.ToLowerUnderScoreFromCamelCase());
            return xStringElement;
        }
    }
}<commit_msg>Fix naming of android output folders when culture has language and country (#13).<commit_after>﻿using System.IO;
using System.Xml.Linq;
using ResxConverter.Core;
using System.Globalization;

namespace ResxConverter.Mobile
{
    public class AndroidResxConverterOutput : IResxConverterOutput
    {
        private string _culture;
        private string _outputProjectFolder;
        private XDocument _xDocument;
        private string _finalOutputPath;

        public AndroidResxConverterOutput(string outputProjectFolder, string culture)
        {
            _outputProjectFolder = outputProjectFolder;
            _culture = culture;

            CreateXml();
        }

        private void CreateXml()
        {
            var cultureSuffix = string.Empty;

            if (!string.IsNullOrEmpty(_culture))
            {
                var cultureInfo = new CultureInfo(_culture);
                if (cultureInfo.IsNeutralCulture)
                {
                    cultureSuffix = $"-{cultureInfo.TwoLetterISOLanguageName}";
                }
                else
                {
                    var regionInfo = new RegionInfo(cultureInfo.LCID);
                    cultureSuffix = $"-{cultureInfo.TwoLetterISOLanguageName}-r{regionInfo.TwoLetterISORegionName}";
                }
            }

            _finalOutputPath = Path.Combine(_outputProjectFolder, $"values{cultureSuffix}", "strings.xml");
            Directory.CreateDirectory(Path.GetDirectoryName(_finalOutputPath));

            _xDocument = new XDocument(new XElement("resources"));
        }

        public void Dispose()
        {
            _xDocument.Save(_finalOutputPath);
        }

        public void WriteComment(string comment)
        {
            _xDocument.Root.Add(new XComment(comment));
        }

        public void WriteString(ResxString stringElement)
        {
            _xDocument.Root.Add(CreateString(stringElement));
        }

        private XElement CreateString(ResxString stringElement)
        {
            var xStringElement = new XElement("string")
            {
                Value = stringElement.Value
            };
            xStringElement.SetAttributeValue("name", stringElement.Key.ToLowerUnderScoreFromCamelCase());
            return xStringElement;
        }
    }
}
{'fraction_non_alphanumeric': 0.078397212543554, 'fraction_numerical': 0.0004977600796416127, 'mean_word_length': 2.0915384615384616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '412251', 'n_tokens_mistral': 1026, 'n_tokens_neox': 970, 'n_words': 189}