PHPackages                             xterr/php-nacecodes - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. xterr/php-nacecodes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xterr/php-nacecodes
===================

Nace Codes

2.0.0(5mo ago)016MITPHPPHP &gt;=7.1 || ^8.0CI passing

Since Jun 17Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/xterr/php-nacecodes)[ Packagist](https://packagist.org/packages/xterr/php-nacecodes)[ RSS](/packages/xterr-php-nacecodes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (5)Used By (0)

PHP NACE Codes
==============

[](#php-nace-codes)

[![PHP Version](https://camo.githubusercontent.com/09a8b7761afdcd28ca1a1bfe447ce82aec524792a7dacb1d3965fbd40ee805f2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e31253230253743253230372e32253230253743253230372e33253230253743253230372e34253230253743253230382e30253230253743253230382e31253230253743253230382e32253230253743253230382e33253230253743253230382e342d3838393242463f6c6f676f3d706870)](https://php.net)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![CI](https://github.com/xterr/php-nacecodes/actions/workflows/ci.yml/badge.svg)](https://github.com/xterr/php-nacecodes/actions/workflows/ci.yml)[![Packagist](https://camo.githubusercontent.com/bd6e26f551dc349d0cc3355c05bf5cca0c826ada1dbdc66601ea11ea8b2babe0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f78746572722f7068702d6e616365636f6465732e737667)](https://packagist.org/packages/xterr/php-nacecodes)

A PHP library for working with NACE (Nomenclature of Economic Activities) codes used by the European Union for classifying business activities.

Features
--------

[](#features)

- Complete NACE Rev. 2 code database
- Hierarchical structure support (Sections, Divisions, Groups, Codes)
- **Multi-language translations** (25 languages included)
- Framework-agnostic translation system with adapters for:
    - Standalone PHP (zero dependencies)
    - Symfony
    - Laravel
- PHP 7.1 - 8.4 support

Installation
------------

[](#installation)

```
composer require xterr/php-nacecodes
```

Quick Start
-----------

[](#quick-start)

### Basic Usage (Without Translations)

[](#basic-usage-without-translations)

```
use Xterr\NaceCodes\NaceCodesFactory;

$factory = new NaceCodesFactory();

// Get all NACE codes
$codes = $factory->getCodes();

// Find a specific code
$code = $codes->getByCodeAndVersion('6201', 2);
echo $code->getName(); // "Computer programming activities"
echo $code->getCode(); // "6201"

// Get sections, divisions, groups
$sections = $factory->getSections();
$section = $sections->getByCodeAndVersion('J', 2);
echo $section->getName(); // "INFORMATION AND COMMUNICATION"

$divisions = $factory->getDivisions();
$groups = $factory->getGroups();
```

### With Translations (Standalone PHP)

[](#with-translations-standalone-php)

The library includes a zero-dependency translator for standalone usage:

```
use Xterr\NaceCodes\NaceCodesFactory;
use Xterr\NaceCodes\Translation\Adapter\ArrayTranslator;

// Create translator with German locale
$translator = new ArrayTranslator(null, 'de');

$factory = new NaceCodesFactory(null, $translator);

$sections = $factory->getSections();
$section = $sections->getByCodeAndVersion('A', 2);

echo $section->getName();      // "AGRICULTURE, FORESTRY AND FISHING" (original)
echo $section->getLocalName(); // "LAND- UND FORSTWIRTSCHAFT, FISCHEREI" (translated)

// Change locale at runtime
$translator->setLocale('fr');

// Get available locales
$locales = $translator->getAvailableLocales();
// ['bg', 'cs', 'da', 'de', 'el', 'es', 'et', 'fi', 'fr', 'hr', 'hu', 'it', 'lt', 'lv', 'mt', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sv', 'tr']
```

### With Symfony Translator

[](#with-symfony-translator)

```
use Xterr\NaceCodes\NaceCodesFactory;
use Xterr\NaceCodes\Translation\Adapter\SymfonyTranslatorAdapter;
use Symfony\Component\Translation\Translator;

// Your existing Symfony translator
$symfonyTranslator = new Translator('de');
// ... configure loaders and resources

$adapter = new SymfonyTranslatorAdapter($symfonyTranslator);
$factory = new NaceCodesFactory(null, $adapter);

$code = $factory->getCodes()->getByCodeAndVersion('0111', 2);
echo $code->getLocalName(); // German translation
```

### With Laravel Translator

[](#with-laravel-translator)

```
use Xterr\NaceCodes\NaceCodesFactory;
use Xterr\NaceCodes\Translation\Adapter\LaravelTranslatorAdapter;

// In a Laravel application
$adapter = new LaravelTranslatorAdapter(app('translator'));
$factory = new NaceCodesFactory(null, $adapter);

$code = $factory->getCodes()->getByCodeAndVersion('0111', 2);
echo $code->getLocalName(); // Translated based on Laravel's locale
```

Available Languages
-------------------

[](#available-languages)

The library includes translations for 25 languages:

CodeLanguageCodeLanguageCodeLanguagebgBulgarianhrCroatianplPolishcsCzechhuHungarianptPortuguesedaDanishitItalianroRomaniandeGermanltLithuanianruRussianelGreeklvLatvianskSlovakesSpanishmtMalteseslSlovenianetEstoniannlDutchsvSwedishfiFinnishnoNorwegiantrTurkishfrFrenchAPI Reference
-------------

[](#api-reference)

### NaceCodesFactory

[](#nacecodesfactory)

```
$factory = new NaceCodesFactory(?string $baseDirectory = null, ?TranslatorInterface $translator = null);

$factory->getCodes();      // Returns NaceCodes
$factory->getSections();   // Returns NaceSections
$factory->getDivisions();  // Returns NaceDivisions
$factory->getGroups();     // Returns NaceGroups
$factory->getMappings();   // Returns NaceCodesMappings
```

### Entity Methods

[](#entity-methods)

All entities (NaceCode, NaceSection, NaceDivision, NaceGroup) share these methods:

```
$entity->getCode();      // NACE code (e.g., "6201", "J", "62", "620")
$entity->getName();      // Original English name
$entity->getLocalName(); // Translated name (falls back to getName() if no translation)
$entity->getVersion();   // NACE version (e.g., 2 for Rev. 2)
```

### Repository Methods

[](#repository-methods)

```
// Get by code and version
$codes->getByCodeAndVersion('6201', 2);
$sections->getByCodeAndVersion('J', 2);
$divisions->getByCodeAndVersion('62', 2);
$groups->getByCodeAndVersion('620', 2);

// Get all by version
$codes->getAllByVersion(2);

// Iteration
foreach ($codes as $code) {
    echo $code->getName();
}

// Count
echo count($codes);
```

### Translator Configuration

[](#translator-configuration)

```
use Xterr\NaceCodes\Translation\Adapter\ArrayTranslator;

$translator = new ArrayTranslator(
    ?TranslationLoaderInterface $loader = null,  // Custom loader (optional)
    ?string $defaultLocale = 'en',               // Default locale
    ?string $fallbackLocale = 'en',              // Fallback when translation not found
    ?string $basePath = null                     // Custom translations path
);

$translator->setLocale('de');
$translator->getLocale();              // 'de'
$translator->setFallbackLocale('en');
$translator->getFallbackLocale();      // 'en'
$translator->getAvailableLocales();    // ['bg', 'cs', ...]
```

Testing
-------

[](#testing)

```
composer install
./vendor/bin/phpunit
```

Requirements
------------

[](#requirements)

- PHP 7.1 or higher
- ext-json

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

Author
------

[](#author)

Razvan Ceana -

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance73

Regular maintenance activity

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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 ~303 days

Total

4

Last Release

153d ago

Major Versions

1.0.2 → 2.0.02025-12-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9526b453abaa7d569fdacdf58cb0f55aa8d889f68f5b622344a28b37eb6c17d?d=identicon)[razvanceana](/maintainers/razvanceana)

---

Top Contributors

[![xterr](https://avatars.githubusercontent.com/u/619509?v=4)](https://github.com/xterr "xterr (9 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xterr-php-nacecodes/health.svg)

```
[![Health](https://phpackages.com/badges/xterr-php-nacecodes/health.svg)](https://phpackages.com/packages/xterr-php-nacecodes)
```

PHPackages © 2026

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