codingseb / Localization

A suite to localize C# and WPF projects easily based on file format you choose.
MIT License
37 stars 6 forks source link

Add support for loading from serialized Json & Yaml strings #9

Closed radj307 closed 11 months ago

radj307 commented 12 months ago

I needed to be able to load translations directly from embedded resources in an assembly without writing them to the disk. Currently, it isn't possible to use the built-in JsonFileLoader & YamlFileLoader to manually load from non-file sources.

This PR implements methods to support loading translations directly from serialized strings, to allow using the parsing capabilities of the built-in file loaders without an actual file.

Usage example:

string serializedJson = "..."; //< this can come from a stream, file, or anywhere else you can get data from

var jsonFileLoader = new JsonFileLoader();
LocalizationLoader.Instance.FileLanguageLoaders.Add(jsonFileLoader);

jsonFileLoader.LoadFromString(serializedJson, LocalizationLoader.Instance);
codingseb commented 11 months ago

Hello @radj307, Thanks a lot for this nice Pull request. The possibility to load from string is very useful.

I merge already this and it will be include in next release.