php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
687 stars 134 forks source link

ISO-8859-1 encoding #190

Closed oscarml closed 6 years ago

oscarml commented 6 years ago

Hi, I've a web app that uses ISO-8859-1 charset

I've created the translations files with i18n-editor, and load translations by fromJsonDictionaryFile

The problem is that files generated by i18n-editor are saved with utf8, and then mi translations are plenty of utf8 characters.

My question is, could I override __() global function in order to apply and utf8_decode call? Do you think there another simplier solution?

Thanks a lot

oscarotero commented 6 years ago

PHP does not allow to override a function defined previously, but you can create your own __() functions and require them, instead using the provided by this library. Just duplicate this file and modify it.

Other option (better in my opinion) is create your own Translator class. Just create a class extending the default Translator overriding or extending the methods you need. This allows to use the default functions but with your own Translator class.

And other option is convert the generated files to ISO-8859-1 charset.

oscarml commented 6 years ago

Thanks a lot, Oscar, I think I'll go for option 2.

El jue., 6 sept. 2018 a las 17:15, Oscar Otero (notifications@github.com) escribió:

PHP does not allow to override a function defined previously, but you can create your own __() functions and require them, instead using the provided by this library. Just duplicate this file https://github.com/oscarotero/Gettext/blob/master/src/translator_functions.php and modify it.

Other option (better in my opinion) is create your own Translator class. Just create a class extending the default Translator https://github.com/oscarotero/Gettext/blob/master/src/Translator.php overriding or extending the methods you need. This allows to use the default functions but with your own Translator class.

And other option is convert the generated files to ISO-8859-1 charset.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oscarotero/Gettext/issues/190#issuecomment-419132332, or mute the thread https://github.com/notifications/unsubscribe-auth/ABuxkqM2N3elS2EXsKT1FM4psvdvEAeAks5uYTv4gaJpZM4Wc25N .