wirecard/io-converter

Includes various adaptable I/O coverters.

1.0.0 2019-06-05 08:18 UTC

This package is auto-updated.

Last update: 2021-05-06 13:49:47 UTC


README

Includes various converters which are adaptable to your needs.

Codacy Badge License PHP v5.6 PHP v7.0 PHP v7.1 PHP v7.2

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.