public void JsonLoadTest(JsonResources resource) { var resourceManager = new ResourceManager(); var json = resourceManager.GetJsonResource(resource); Assert.NotNull(json); }
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); }
public static ProtoCollection Fetch() { List <ProtoCard> cards = JsonResources.Load <ProtoCard>(_cardsPath); List <ProtoSpecialCard> specialCards = JsonResources.Load <ProtoSpecialCard>(_specialCardsPath); List <ProtoCharacter> characters = JsonResources.Load <ProtoCharacter>(_charactersPath); List <ProtoImage> images = JsonResources.Load <ProtoImage>(_imagesPath); Debug.Log("[LocalCollection] Loaded " + cards.Count + " cards"); Debug.Log("[LocalCollection] Loaded " + specialCards.Count + " special cards"); Debug.Log("[LocalCollection] Loaded " + characters.Count + " characters"); Debug.Log("[LocalCollection] Loaded " + images.Count + " images"); return(new ProtoCollection(cards, specialCards, characters, images)); }
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); }
public static ConverterLogger Convert(ResxToJsonConverterOptions options) { var logger = new ConverterLogger(); IDictionary <string, ResourceBundle> bundles = null; if (options.InputFiles.Count > 0) { bundles = ResxHelper.GetResources(options.InputFiles, logger); } if (options.InputFolders.Count > 0) { var bundles2 = ResxHelper.GetResources(options.InputFolders, options.Recursive, logger); if (bundles == null) { bundles = bundles2; } else { // join two bundles collection foreach (var pair in bundles2) { bundles[pair.Key] = pair.Value; } } } if (bundles == null || bundles.Count == 0) { logger.AddMsg(Severity.Warning, "No resx files were found"); return(logger); } logger.AddMsg(Severity.Trace, "Found {0} resx bundles", bundles.Count); if (bundles.Count > 1 && !String.IsNullOrEmpty(options.OutputFile)) { // join multiple resx resources into a single js-bundle var bundleMerge = new ResourceBundle(Path.GetFileNameWithoutExtension(options.OutputFile)); foreach (var pair in bundles) { bundleMerge.MergeWith(pair.Value); } logger.AddMsg(Severity.Trace, "As 'outputFile' option was specified all bundles were merged into single bundle '{0}'", bundleMerge.BaseName); bundles = new Dictionary <string, ResourceBundle> { { bundleMerge.BaseName, bundleMerge } }; } foreach (ResourceBundle bundle in bundles.Values) { JsonResources jsonResources = generateJsonResources(bundle, options); string baseFileName; string baseDir; if (!string.IsNullOrEmpty(options.OutputFile)) { baseFileName = Path.GetFileName(options.OutputFile); baseDir = Path.GetDirectoryName(options.OutputFile); } else { baseFileName = bundle.BaseName.ToLowerInvariant() + GetOutputFileExtension(options.OutputFormat); baseDir = options.OutputFolder; } if (string.IsNullOrEmpty(baseDir)) { baseDir = Environment.CurrentDirectory; } logger.AddMsg(Severity.Trace, "Processing '{0}' bundle (contains {1} resx files)", bundle.BaseName, bundle.Cultures.Count); string dirPath = options.OutputFormat == OutputFormat.i18next ? Path.Combine(baseDir, options.FallbackCulture) : baseDir; string outputPath = Path.Combine(dirPath, baseFileName); string jsonText = stringifyJson(jsonResources.BaseResources, options); writeOutput(outputPath, jsonText, options, logger); if (jsonResources.LocalizedResources.Count > 0) { foreach (KeyValuePair <string, JObject> pair in jsonResources.LocalizedResources) { dirPath = Path.Combine(baseDir, pair.Key); outputPath = Path.Combine(dirPath, baseFileName); jsonText = stringifyJson(pair.Value, options); writeOutput(outputPath, jsonText, options, logger); } } } return(logger); }
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; }
public T GetDesrializedJsonResource <T>(JsonResources resourceName) { return(JsonConvert.DeserializeObject <T>(GetJsonResource(resourceName))); }
public string GetJsonResource(JsonResources resourceName) { return(LoadFile(resourceName + ".json", reader => reader.ReadToEnd())); }