polyfill-intl-normalizer
Symfony polyfill for intl's Normalizer class and related functions
Top Related Projects
Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
Provides access to the localization data of the ICU library
PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.
Quick Overview
The symfony/polyfill-intl-normalizer is a PHP library that provides a polyfill for the Intl Normalizer. It aims to implement the PHP intl extension's Normalizer class for environments where the intl extension is not available or installed. This library is part of the larger Symfony Polyfill project, which offers various polyfills for PHP features.
Pros
- Enables use of Normalizer functionality without the intl extension
- Compatible with multiple PHP versions (5.3.3+)
- Lightweight and easy to integrate
- Maintained by the Symfony community, ensuring reliability and updates
Cons
- May have slightly lower performance compared to the native intl extension
- Not a complete replacement for all intl extension features
- Requires additional setup and maintenance compared to using the native extension
- May become obsolete as PHP versions advance and intl becomes more widely available
Code Examples
- Basic string normalization:
use Symfony\Polyfill\Intl\Normalizer\Normalizer;
$string = "Caf\xC3\xA9";
$normalized = Normalizer::normalize($string, Normalizer::FORM_C);
echo $normalized; // Outputs: Café
- Checking if a string is already normalized:
use Symfony\Polyfill\Intl\Normalizer\Normalizer;
$string = "Caf\xC3\xA9";
$isNormalized = Normalizer::isNormalized($string, Normalizer::FORM_C);
var_dump($isNormalized); // Outputs: bool(true)
- Normalizing to decomposed form:
use Symfony\Polyfill\Intl\Normalizer\Normalizer;
$string = "Café";
$decomposed = Normalizer::normalize($string, Normalizer::FORM_D);
echo bin2hex($decomposed); // Outputs: 4361666565cc81
Getting Started
To use symfony/polyfill-intl-normalizer in your project:
-
Install the library using Composer:
composer require symfony/polyfill-intl-normalizer
-
In your PHP code, use the Normalizer class:
use Symfony\Polyfill\Intl\Normalizer\Normalizer; $normalized = Normalizer::normalize($yourString, Normalizer::FORM_C);
The library will automatically provide the Normalizer functionality if the intl extension is not available in your PHP environment.
Competitor Comparisons
Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
Pros of polyfill-intl-idn
- Provides IDN (Internationalized Domain Names) functionality for systems without the
intl
extension - Supports IDNA2008 standard for domain name handling
- Offers a lightweight alternative to the full
intl
extension for IDN-specific needs
Cons of polyfill-intl-idn
- Limited to IDN functionality, while polyfill-intl-normalizer covers broader Unicode normalization
- May have slightly lower performance compared to native
intl
extension implementations - Requires additional dependencies for full functionality (e.g., symfony/polyfill-mbstring)
Code Comparison
polyfill-intl-idn:
use Symfony\Polyfill\Intl\Idn\Idn;
$ascii = Idn::idn_to_ascii('mañana.com');
$unicode = Idn::idn_to_utf8('xn--maana-pta.com');
polyfill-intl-normalizer:
use Symfony\Polyfill\Intl\Normalizer\Normalizer;
$normalized = Normalizer::normalize('café', Normalizer::FORM_C);
$isNormalized = Normalizer::isNormalized('café', Normalizer::FORM_C);
Both polyfills provide fallback implementations for PHP environments lacking the intl
extension. polyfill-intl-idn focuses on IDN conversion and handling, while polyfill-intl-normalizer offers broader Unicode normalization capabilities. Choose based on your specific needs: IDN support or general Unicode normalization.
Provides access to the localization data of the ICU library
Pros of intl
- Full-featured internationalization library with extensive language and locale support
- Provides robust number formatting, currency handling, and date/time manipulation
- Offers additional utilities like country and language information
Cons of intl
- Larger package size due to comprehensive feature set
- May have higher performance overhead for simple normalization tasks
- Requires the PHP Intl extension to be installed
Code Comparison
polyfill-intl-normalizer:
use Symfony\Polyfill\Intl\Normalizer\Normalizer;
$normalized = Normalizer::normalize($string, Normalizer::FORM_C);
intl:
use Symfony\Component\Intl\Normalizer\Normalizer;
$normalized = Normalizer::normalize($string, Normalizer::FORM_C);
$formatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
$formatted = $formatter->format(1234.56);
Summary
polyfill-intl-normalizer is a lightweight solution focused solely on Unicode normalization, making it ideal for projects with minimal internationalization needs. It's particularly useful when the PHP Intl extension is unavailable.
intl, on the other hand, is a comprehensive internationalization library offering a wide range of features beyond normalization. It's better suited for projects requiring extensive localization and formatting capabilities, but comes with a larger footprint and additional dependencies.
Choose based on your project's specific internationalization requirements and performance considerations.
PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.
Pros of forceutf8
- Simpler and more lightweight, focusing specifically on UTF-8 encoding
- Provides additional utility functions for handling UTF-8 strings
- Easy to use without dependencies
Cons of forceutf8
- Less comprehensive than polyfill-intl-normalizer for Unicode normalization
- Not part of a larger ecosystem like Symfony
- May not be as actively maintained or widely used
Code Comparison
forceutf8:
$utf8_string = Encoding::toUTF8($string);
$ascii_string = Encoding::toASCII($utf8_string);
polyfill-intl-normalizer:
$normalized = Normalizer::normalize($string, Normalizer::FORM_C);
$isNormalized = Normalizer::isNormalized($string, Normalizer::FORM_C);
The forceutf8 library focuses on converting strings to UTF-8 and ASCII, while polyfill-intl-normalizer provides Unicode normalization functions. polyfill-intl-normalizer offers a more standardized approach to string normalization, following the Intl extension's API. forceutf8 is more suitable for simple UTF-8 conversion tasks, while polyfill-intl-normalizer is better for applications requiring full Unicode normalization support.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Symfony Polyfill / Intl: Normalizer
This component provides a fallback implementation for the
Normalizer
class provided
by the Intl extension.
More information can be found in the main Polyfill README.
License
This library is released under the MIT license.
Top Related Projects
Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
Provides access to the localization data of the ICU library
PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot