PHPackages                             moss/locale - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. moss/locale

AbandonedI18n[Localization &amp; i18n](/categories/localization)

moss/locale
===========

moss locale

v2.0(11y ago)67501MITPHPPHP &gt;=5.4

Since Nov 22Pushed 11y ago1 watchersCompare

[ Source](https://github.com/mossphp/moss-locale)[ Packagist](https://packagist.org/packages/moss/locale)[ RSS](/packages/moss-locale/feed)WikiDiscussions dev Synced today

READMEChangelog (2)Dependencies (1)Versions (4)Used By (1)

Moss Locale
===========

[](#moss-locale)

[![Build Status](https://camo.githubusercontent.com/c23d982de021a0fc3f1a380d3d67111151f64a3f04a20389e416a9b4b7c9cff1/68747470733a2f2f7472617669732d63692e6f72672f6d6f73737068702f6d6f73732d6c6f63616c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/mossphp/moss-locale)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9e74b5744aa011ab35f909b34c20aa6b24cb6d034fb6c746fe5facda5d45fd00/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6f73737068702f6d6f73732d6c6f63616c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mossphp/moss-locale/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/6163fa2e45ddc9c742a9b49b19d2a35bf8ba2cad91884808cc524b3d474acddb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6f73737068702f6d6f73732d6c6f63616c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mossphp/moss-locale/?branch=master)

Basic tool for handling translations, formatting and stuff.

Locale
------

[](#locale)

Class that handles locale name, timezone and currency sub unit.

```
	$locale = new Locale('en_GB', 'UTC', 100);

	echo $locale->locale(); // will print "en_GB"
	$locale->locale('en_US'); // will change locale to en_US

	echo $locale->language(); // will print "en"
	echo $locale->territory(); // will print "GB"

	echo $locale->currencySubUnit(); // will print 100
	$locale->currencySubUnit(1000); // will change sub unit to 1000

	echo $locale->timezone(); // will print "UTC"
	$locale->timezone('Europe/Berlin'); will change default timezone (used by all date functions) to 'Europe/Berlin'
```

Translator
----------

[](#translator)

Translator translates simple texts, singular and plural, with optional placeholders.

```
	$translator = new Translator('en_GB', []);
```

Translator uses dictionaries as source of translations Lower priority value is better - 0 means highest priority.

```
	$dictionary = new ArrayDictionary('en_GB', ['dude' => 'laddy']);
	$translator = new Translator('en_GB', $dictionary);
```

Dictionaries are list of key-value pairs, where key is a word/sentence/identifier and is translated text. Eg. EN to DE:

```
	[
		'There be %placeholder%' => 'dort %placeholder%',
		'welcome.string' => 'Hallo %name%!'
	]
```

```
	echo $translator->trans('There be %placeholder%', ['placeholder' => 'Drachen'])
	// prints dort Drachen
```

For plural translation additional syntax is used in dictionaries to describe intervals with proper translations. Plural translations also support placeholders. Intervals follow ISO 31-11 notation:

```
[, ]	[a, b]	closed interval in ℝ from a (included) to b (included)
], ]	]a, b]	left half-open interval in ℝ from a (excluded) to b (included)
[, [	[a, b[	right half-open interval in ℝ from a (included) to b (excluded)
], [	]a, b[	open interval in ℝ from a (excluded) to b (excluded)

```

```
	[
		'apple.count' => '{0} There are no apples|{1} There is one apple|]1,19] There are %count% apples|[20,Inf] There are many apples'
	]
```

```
	echo $translator->transChoice('apple.count', $count)
	// prints There are no apples when $count = 0
	// prints There is one apple when $count = 1
	// prints There are %count% apples when $count > 1 && $count >= 19
	// prints There are many apples when $count >= 20
```

Translator comes with `MultiDictionary` class that allows for combining multiple dictionaries as one. For example, when default translations come from files, and they can be changed in database. `MultiDictionary` allows for prioritizing dictionaries. Usually you pass dictionaries trough constructor, and such case first dictionary with requested translation wins. But there are situations where dictionaries are added after instantiation, just when adding new dictionary provide its priority. If not - it will be added as last one. Lower number is better - 0 is highest priority.

```
	$multi = new MultiDictionary('en_GB');
	$multi->addDictionary($dictionary, 0);
```

Formatter
---------

[](#formatter)

Formatter provides set of functions for formatting numbers, currencies and datetime values.

- `::formatNumber($number)`
- `::formatCurrency($amount)`
- `::formatTime(\DateTime $datetime)`
- `::formatDate(\DateTime $datetime)`
- `::formatDateTime(\DateTime $datetime)`

Locale comes with two formatter implementations: `Intl` that requires extension and plain php formatter.

`PlainFormatter` can be configured to meet your needs:

```
   $formatter = new PlainFormatter('en_GB', 100, 'UTC', [
       'number' = '#,##0.###',
       'currency' = '#,##0.##£',
       'date' = 'n/j/y',
       'time' = 'g:i A',
       'datetime' = 'n/j/y, g:i A'
   ]);
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~125 days

Total

2

Last Release

4116d ago

Major Versions

v1.0 → v2.02015-03-27

PHP version history (2 changes)v1.0PHP &gt;=5.3.4

v2.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8addaf28c1a25afd6006377779228ee980528e4ca23793a4ab8bc426dda5018b?d=identicon)[potfur](/maintainers/potfur)

---

Top Contributors

[![potfur](https://avatars.githubusercontent.com/u/1244857?v=4)](https://github.com/potfur "potfur (34 commits)")

---

Tags

internationalizationi18ntranslationlocale

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/moss-locale/health.svg)

```
[![Health](https://phpackages.com/badges/moss-locale/health.svg)](https://phpackages.com/packages/moss-locale)
```

###  Alternatives

[fightbulc/moment

Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js

9683.4M13](/packages/fightbulc-moment)[tractorcow/silverstripe-fluent

Simple localisation for Silverstripe

91437.9k29](/packages/tractorcow-silverstripe-fluent)[aplus/language

Aplus Framework Language Library

2391.7M15](/packages/aplus-language)[skillshare/formatphp

Internationalize PHP apps. This library provides an API to format dates, numbers, and strings, including pluralization and handling translations.

8032.4k](/packages/skillshare-formatphp)[delight-im/i18n

Internationalization and localization for PHP

595.4k3](/packages/delight-im-i18n)[jrmajor/fluent

Fluent localization system for PHP

2918.2k7](/packages/jrmajor-fluent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
