# LocalizedToNormalized

This filter will change any given localized input to it's normalized representation. It uses in Background `Zend_Locale` to do this transformation for you.

This allows your user to enter informations in his own language notation, and you can then store the normalized value into your database for example.

Please note that normalization is not equal to translation. This filter can not translate strings from one language into another like you could expect with months or names of days.

The following input types can be normalized:

- integer: Integer numbers, which are localized, will be normalized to the english notation.

- float: Float numbers, which are localized, will be normalized to the english notation.

- numbers: Other numbers, like real, will be normalized to the english notation.

- time: Time values, will be normalized to a named array.

- date: Date values, will be normalized to a named array.

Any other input will be returned as it, without changing it.

You should note that normalized output is always given as string. Otherwise your environment would transfer the normalized output automatically to the notation used by the locale your environment is set to.

## Normalization for numbers

Any given number like integer, float or real value, can be normalized. Note, that numbers in scientific notation, can actually not be handled by this filter.

So how does this normalization work in detail for numbers:

    // Initiate the filter
    $filter = new Zend_Filter_LocalizedToNormalized();
    $filter->filter('123.456,78');
    // returns the value '123456.78'

Let's expect you have set the locale 'de' as application wide locale. `Zend_Filter_LocalizedToNormalized` will take the set locale and use it to detect which sort of input you gave. In our example it was a value with precision. Now the filter will return you the normalized representation for this value as string.

You can also control how your normalized number has to look like. Therefor you can give all options which are also used by `Zend_Locale_Format`. The most common are:

- date_format

- locale

- precision

For details about how these options are used take a look into this Zend_Locale chapter.

Below is a example with defined precision so you can see how options work:

    // Numeric Filter
    $filter = new Zend_Filter_LocalizedToNormalized(array('precision' => 2));

    $filter->filter('123.456');
    // returns the value '123456.00'

    $filter->filter('123.456,78901');
    // returns the value '123456.79'

## Normalization for date and time

Input for date and time values can also be normalized. All given date and time values will be returned as array, where each date part is given within a own key.

    // Initiate the filter
    $filter = new Zend_Filter_LocalizedToNormalized();
    $filter->filter('12.April.2009');
    // returns array('day' => '12', 'month' => '04', 'year' => '2009')

Let's expect you have set the locale 'de' again. Now the input is automatically detected as date, and you will get a named array in return.

Of course you can also control how your date input looks like with the date_format and the locale option.

    // Date Filter
    $filter = new Zend_Filter_LocalizedToNormalized(
        array('date_format' => 'ss:mm:HH')
    );

    $filter->filter('11:22:33');
    // returns array('hour' => '33', 'minute' => '22', 'second' => '11')