kado/kado.locale

PHP locale library.

Maintainers

Package info

github.com/sweet-andi/kado.locale

pkg:composer/kado/kado.locale

Statistics

Installs: 3

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2026-03-31 13:35 UTC

This package is auto-updated.

Last update: 2026-03-31 13:48:32 UTC


README

Locale class and some helpers

Installation

inside composer.json:

{
   "require": {
      "php": ">=8.3",
      "kado/kado.locale": "^1.0"
   }
}

Usage

If you want to use this package inside you're application include the depending composer autoload.php

The Locale

Create a new Locale instance

use \Kado\Locale\Locale;

Locale::Create(
   // The fallback locale if no other was found
   new Locale( 'de', 'AT', 'UTF-8' ),
   // Check also the URL path for a locale or language part?
   true,
   // These are the names of the parameters, accepted from $_POST, $_GET and $_SESSION
   [ 'locale', 'language', 'lang' ]
)
   ->registerAsGlobalInstance();

This creates the new Locale by checking the following places to get the required information

  • First The current URL part is checked, if it contains a valid locale string, it is used (you can disable it by setting the 2nd Create parameter to FALSE.
  • Next it checks if one of the defined request parameters (3rd parameter) is defined by $_POST, $_GET or $_SESSION
  • After that, its checked if the browser sends some information about the preferred locale/language.
  • Finally, it is checked if the system gives usable locale information.

If all this methods fail, the declared fallback locale is returned. You can also call it main locale.

Last but not least the created locale is registered as global available Locale instance. It can be accessed from other places by:

if ( Locale::HasGlobalInstance() )
{
   $locale = Locale::GetGlobalInstance();
}
else
{
   // Create the locale
   //$locale = Locale::Create( … )->registerAsGlobalInstance();
}