コード例 #1
0
        private static JsonResources generateJsonResources(IResxToJsonFormatter formatter, ResourceBundle bundle,
                                                           ResxToJsonConverterOptions options)
        {
            var result = new JsonResources();
            // root resoruce
            IDictionary <string, string> baseValues = bundle.GetValues(null);
            JObject jBaseValues = convertValues(baseValues, options);

            result.BaseResources = formatter.GetJsonResource(jBaseValues, CultureInfo.InvariantCulture, bundle, options);

            // culture specific resources
            foreach (CultureInfo culture in bundle.Cultures)
            {
                if (culture.Equals(CultureInfo.InvariantCulture))
                {
                    continue;
                }

                IDictionary <string, string> values = bundle.GetValues(culture);
                if (options.UseFallbackForMissingTranslation)
                {
                    foreach (var baseValue in baseValues)
                    {
                        if (!values.ContainsKey(baseValue.Key))
                        {
                            values[baseValue.Key] = baseValues[baseValue.Key];
                        }
                    }
                }
                JObject jCultureValues = convertValues(values, options);
                result.LocalizedResources[culture] = formatter.GetJsonResource(jCultureValues, culture, bundle, options);
            }
            return(result);
        }
コード例 #2
0
        private static JsonResources generateJsonResources(ResourceBundle bundle, ResxToJsonConverterOptions options)
        {
            var result = new JsonResources();
            // root resoruce
            IDictionary <string, string> baseValues = bundle.GetValues(null);
            JObject jBaseValues = convertValues(baseValues, options);

            switch (options.OutputFormat)
            {
            case OutputFormat.RequireJs:
                // When dealing with require.js i18n the root resource contains a "root" subnode that contains all
                // of the base translations and then a bunch of nodes like the following for each supported culture:
                //   "en-US" : true
                //   "fr" : true
                //   ...
                var jRoot = new JObject();
                jRoot["root"] = jBaseValues;
                foreach (CultureInfo culture in bundle.Cultures)
                {
                    if (culture.Equals(CultureInfo.InvariantCulture))
                    {
                        continue;
                    }
                    jRoot[culture.Name] = true;
                }
                result.BaseResources = jRoot;
                break;

            default:
                // In the simplest case our output format is plain vanilla json (just a kvp dictionary)
                result.BaseResources = jBaseValues;
                break;
            }

            // culture specific resources
            foreach (CultureInfo culture in bundle.Cultures)
            {
                if (culture.Equals(CultureInfo.InvariantCulture))
                {
                    continue;
                }
                IDictionary <string, string> values = bundle.GetValues(culture);
                JObject jCultureValues = convertValues(values, options);
                result.LocalizedResources[culture.Name] = jCultureValues;
            }
            return(result);
        }
コード例 #3
0
 public void MergeWith(ResourceBundle other)
 {
     // NOTE: Cultures includes InvarianCulture for root resources as well
     foreach (var culture in other.Cultures)
     {
         AddResources(culture, other.GetValues(culture));
     }
 }
コード例 #4
0
 public void MergeWith(ResourceBundle other)
 {
     // NOTE: Cultures includes InvarianCulture for root resources as well
     foreach (var culture in other.Cultures)
     {
         AddResources(culture, other.GetValues(culture));
     }
 }
コード例 #5
0
        private static JsonResources generateJsonResources(ResourceBundle bundle, ResxToJsonConverterOptions options)
        {
            var result = new JsonResources();
            // root resoruce
            IDictionary<string, string> baseValues = bundle.GetValues(null);
            JObject jBaseValues = convertValues(baseValues, options);
            switch (options.OutputFormat)
            {
                case OutputFormat.RequireJs:
                    // When dealing with require.js i18n the root resource contains a "root" subnode that contains all
                    // of the base translations and then a bunch of nodes like the following for each supported culture:
                    //   "en-US" : true
                    //   "fr" : true
                    //   ...
                    var jRoot = new JObject();
                    jRoot["root"] = jBaseValues;
                    foreach (CultureInfo culture in bundle.Cultures)
                    {
                        if (culture.Equals(CultureInfo.InvariantCulture))
                            continue;
                        jRoot[culture.Name] = true;
                    }
                    result.BaseResources = jRoot;
                    break;
                default:
                    // In the simplest case our output format is plain vanilla json (just a kvp dictionary)
                    result.BaseResources = jBaseValues;
                    break;
            }

            // culture specific resources
            foreach (CultureInfo culture in bundle.Cultures)
            {
                if (culture.Equals(CultureInfo.InvariantCulture))
                    continue;
                IDictionary<string, string> values = bundle.GetValues(culture);
                JObject jCultureValues = convertValues(values, options);
                result.LocalizedResources[culture.Name] = jCultureValues;
            }
            return result;
        }