コード例 #1
0
        public virtual Task <ComposedLocaleResource> ComposeLocaleResourceAsync(LocaleResource resource)
        {
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(resource.Name);

            if (String.IsNullOrEmpty(fileNameWithoutExtension))
            {
                return(null);
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Composing locale file found at '{0}', attempting to load.", resource.Path);
            }

            var configurationContainer =
                new ConfigurationBuilder()
                .SetBasePath(_fileSystem.RootPath)
                .AddJsonFile(_fileSystem.Combine(resource.Location, fileNameWithoutExtension + ".json"), false)
                .AddXmlFile(_fileSystem.Combine(resource.Location, fileNameWithoutExtension + ".xml"), true)
                .AddYamlFile(_fileSystem.Combine(resource.Location, fileNameWithoutExtension + ".txt"), true);
            var config = configurationContainer.Build();

            var composedLocaleResource = new ComposedLocaleResource
            {
                LocaleResource = resource
            };


            switch (fileNameWithoutExtension.ToLower())
            {
            case EmailsFileName:
            {
                composedLocaleResource.Configure <LocaleEmail>(model => new LocalizedValues <LocaleEmail>
                    {
                        Resource = resource,
                        Values   = EmailsSerializer.Parse(config)
                    });
                break;
            }

            default:
            {
                composedLocaleResource.Configure <LocaleString>(model => new LocalizedValues <LocaleString>
                    {
                        Resource = resource,
                        Values   = StringSerializer.Parse(config)
                    });
                break;
            }
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Completed composing locale files found in '{0}'.", resource.Path);
            }

            return(Task.FromResult(composedLocaleResource));
        }
コード例 #2
0
 /// <summary>
 ///     Adds a Locale Resource to the system for the specified culture and type. Defaults the value to the name of the item if the value isnt passed in
 /// </summary>
 /// <param name="name">Name of hte resource item</param>
 /// <param name="type">Type of the item (Glossary, config, etc)</param>
 /// <param name="cultureCode">Culture code for the resource (en-US, etc)</param>
 /// <param name="value">(Optional) Value for the resource</param>
 public static void AddLocaleResource(string name, string type, string cultureCode, string value = null)
 {
     using (var pemsRbacContext = new PEMRBACEntities())
     {
         //create the item and add it to the system
         var item = new LocaleResource
         {
             CultureCode = cultureCode,
             Name        = name,
             Value       = value ?? name,
             Type        = type
         };
         pemsRbacContext.LocaleResources.Add(item);
         pemsRbacContext.SaveChanges();
     }
 }
コード例 #3
0
    public static void Load(string locale)
    {
        var textAsset = Resources.Load(string.Format(RESOURCE_DIR, locale)) as TextAsset;

        if (textAsset == null)
        {
            Debug.LogErrorFormat("[LocalizationSystem] There is no resource in : {0}", string.Format("Assets/Resource/{0}", string.Format(RESOURCE_DIR, locale)));
            return;
        }

        XmlSerializer xmlSerializer = new XmlSerializer(typeof(LocaleResource));

        try
        {
            Dictionary <string, string> stringById = new Dictionary <string, string>();
            LocaleResource localeResource          = xmlSerializer.Deserialize(new StringReader(textAsset.text)) as LocaleResource;

            foreach (LocaleString localeString in localeResource.StringList)
            {
                if (stringById.ContainsKey(localeString.Name))
                {
                    continue;
                }

                stringById.Add(localeString.Name, localeString.Text);
            }

            _stringById = stringById;
        }
        catch (Exception ex)
        {
            Debug.LogErrorFormat("[LocalizationSystem] There is syntax error in : {0}", string.Format("Assets/Resource/{0}", string.Format(RESOURCE_DIR, locale)));
        }

        onLocalChanged?.Invoke();
    }
コード例 #4
0
        public LocaleResourceTests()
        {
            IZendeskApiClient client = new DisposableZendeskApiClient <Locale>(resource => new LocaleResourceSampleSite(resource));

            _resource = new LocaleResource(client, NullLogger.Instance);
        }
コード例 #5
0
 public static void Update(this LocaleResource target, LocaleResource source)
 {
     target.LanguageId    = source.LanguageId;
     target.ResourceName  = source.ResourceName;
     target.ResourceValue = source.ResourceValue;
 }
コード例 #6
0
 public static void Update(this LocaleResource model, LocaleResourceForm form)
 {
     model.ResourceName = form.ResourceName;
 }
コード例 #7
0
 public void InsertLocaleStringResource(LocaleResource localeResource)
 {
     _unitOfwork.LocaleResourceRepository.Add(localeResource);
     _unitOfwork.SaveChanges();
 }