wirecard / io-converter
Includes various adaptable I/O coverters.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2023-01-06 17:17:16 UTC
README
Includes various converters which are adaptable to your needs.
Included Converters
- WppVTwoConverter
- JsonConverter
Installation
The library can be installed using Composer. If you have not installed Composer, you can follow the offical instructions.
Once composer is installed, run this in your terminal/command-line tool:
composer require wirecard/io-converter
Wirecard WPP v2 Converter
WPP v2 converter can be used to convert country-language codes from ISO-639-1 and from ISO-639-1 combined with ISO-3166 Alpha-2/Alpha-3 to WPP v2 supported language codes.
Usage
In your application load the vendor/autoload.php
that Composer provides.
You can then initialize the WppVTwoConverter
class like so:
use Wirecard\Converter\WppVTwoConverter; $converter = new WppVTwoConverter(); $converter->init();
This automatically loads all the supported language codes for WPP v2.
Conversion
The WPP v2 converter does support two types of input formats:
- ISO-639-1 (e.g. "en")
- ISO-639-1 - ISO-3166 (e.g. "en-US")
If the given input is valid, but is not supported within WPP v2 yet, the converter will return a fallback language. If the input is valid and supported the converter will return the correct code for usage within WPP v2.
(The fallback language code is default set to "en")
To convert your language codes to WPP v2 supported codes use the specified input formats and call the convert function:
$converter->convert("en-US"); // => "en"
$converter->convert("de"); // => "de"
If you pass a correct formatted language code which is not supported yet by WPP v2 you will get the fallback language code:
$converter->convert("zz"); // => "en"
Furthermore there is the possibility to set your own fallback language to "de" for example with $converter->setFallback('de')
.
Please ensure that the language code you want to set as fallback is supported by WPP v2, else the fallback setting will not work.
Exceptions
Note that you have to send a valid language code format,
otherwise you will receive an InvalidArgumentException
:
$converter->convert("en-USUS"); // => InvalidArgumentException
The correct format for input language code can be xx
or xx-XX
or xx-XXX
.