Kajabity / Kajabity-Tools

A collection of miscellaneous code utilities and snippets.
http://kajabity.com/kajabity-tools/
18 stars 11 forks source link

Added encoding support to JavaPropertyReader #3

Closed stackh34p closed 8 years ago

stackh34p commented 8 years ago

Based on one of the TODO items in the JavaPropertyReader.cs I added a few changes to make it work with encoding.

This allows for the ability to load and work with property files that have been saved with a different encoding (UTF-8 for example). In some scenarios (GWT internationalisation and i18n in general) ISO-8859-1 is not very appropriate and in such cases many vendors (Google themselves with GWT) encourage use of different encoding (mostly UTF8).

The JavaProperties' Load the JavaPropertyReader's Parse methods now have an overload that allows passing an encoding object that should be used to read the properties file. If null is passed, the standard encoding (ISO-8859-1) will be used instead.

Kajabity commented 8 years ago

Thanks for that ivaylo5ev - one less task to complete. I'll also merge my 'next-release' branch in which should fix the AppVeyor build issue - and generate the master branch NuGet's.

Kajabity commented 8 years ago

I'd also be interested if you had a sample file that could be used in an NUnit test. And would there be any use in a Store method supporting alternate encodings?

stackh34p commented 8 years ago

Hi, I will commit some unit tests with sample files in Cyrillic which I was working with in the coming days.

As for storing properties files with encoding, I think this would also be of good use. You can open properties files in desired encoding, and store them in ISO-8859-1 with unicode escape sequences (\uxxxx) applied to non-unicode symbols. The vice-versa is also useful if you want to revisit an escaped file. This has real application in localisation where all native characters are escaped (such as the Cyrillic symbols), and meaningful edits can no-longer be applied to the properties file unless reverted back to unicode encoding (like Utf-8).

I might also give you a hand with the PropertyWriter to support encodings as well in another pull request.

Regards,