Пример #1
0
        public static void Initialize(LocalizerConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _blocks = new Dictionary <string, Block>(StringComparer.InvariantCultureIgnoreCase);
            Build(configuration);
        }
Пример #2
0
        private static void Build(LocalizerConfiguration configuration)
        {
            var pattern = string.IsNullOrWhiteSpace(configuration.Pattern)
                ? "*.json"
                : $"{configuration.Pattern}.*.json";
            var searchOption = configuration.ReadNestedFolders
                ? SearchOption.AllDirectories
                : SearchOption.TopDirectoryOnly;

            var files = Directory.GetFiles(configuration.Path, pattern, searchOption);

            foreach (var file in files)
            {
                var localeRegex = new Regex(@"^([A-Za-z]{1,})\.([A-Za-z]{2}-[A-Za-z]{2}|any)\.json$");
                var filename    = Path.GetFileName(file);
                var match       = localeRegex.Match(filename);
                if (match.Success)
                {
                    var blockName     = match.Groups[1].Value;
                    var cultureString = match.Groups[^ 1]?.Value;