PHPackages                             zubs/translator - 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. zubs/translator

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

zubs/translator
===============

A simple Laravel package that can translate between languages

v1.0.0(2y ago)23[1 issues](https://github.com/Zubs/translation/issues)ISCPHP

Since Oct 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Zubs/translation)[ Packagist](https://packagist.org/packages/zubs/translator)[ RSS](/packages/zubs-translator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Zubs/Translator
===============

[](#zubstranslator)

A simple Laravel package that can translate between languages.

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

[](#installation)

You can install this package via composer using this command:

```
composer require zubs/translator
```

Then, the service provider is automatically registered.

Usage
-----

[](#usage)

### Methods

[](#methods)

This package provides the `Zubs\Translator\Translate` and that provides the following methods:

- [`getLanguages()`](#get-all-available-languages-with-getlanguages)
- [`getLanguageCodes()`](#get-the-language-codes-of-all-available-languages-with-getlanguagecodes)
- [`detectLanguage()`](#detect-the-language-of-a-string-with-detectlanguage)
- [`translate()`](#translate-a-string-with-translate)

> All the methods cache results for better performances. The cache defaults to 24hrs but can be changed by passing an extra parameter to the methods.

#### Get all available languages with `getLanguages()`

[](#get-all-available-languages-with-getlanguages)

This function definition looks like this:

```
public function getLanguages(string $target = 'en', int $ttl = self::DEFAULT_CACHE_TIME): array
```

The `target` parameter is optional and defaults to `en`. This is the language that the returned array will be translated to. The `ttl` is used to set the time that the cache will be stored for. It defaults to 1 day.

The function returns an array of all available languages in the format, `code => language`, like this:

```
[
    'en' => 'English',
    'fr' => 'French',
    'es' => 'Spanish',
]
```

#### Get the language codes of all available languages with `getLanguageCodes()`

[](#get-the-language-codes-of-all-available-languages-with-getlanguagecodes)

This function definition looks like this:

```
public function getLanguageCodes(int $ttl = self::DEFAULT_CACHE_TIME): array
```

This function takes just one parameter, `ttl`, and returns the same array as the `getLanguages()` function, but without the language names. Like this:

```
[
    'en',
    'fr',
    'es',
]
```

The `ttl` is used to set the time that the cache will be stored for. It defaults to 1 day.

#### Detect the language of a string with `detectLanguage()`

[](#detect-the-language-of-a-string-with-detectlanguage)

This function definition looks like this:

```
public function detectLanguage(string $text, int $ttl = self::DEFAULT_CACHE_TIME): string
```

This function takes a mandatory string, `text` as a parameter. It also takes an optional parameter, `ttl`. The `ttl` is used to set the time that the cache will be stored for. It defaults to 1 day. The function returns the language code of the language that the string is written in. Like this:

```
detectLanguage('Hello world!'); // returns 'en'
```

#### Translate a string with `translate()`

[](#translate-a-string-with-translate)

This function definition looks like this:

```
public function translate
(
    string $text,
    string $to,
    string $from = null,
    int $ttl = self::DEFAULT_CACHE_TIME
): string
```

This function takes a mandatory string, `text`, as a parameter and returns the translated string. The `to` parameter is the language code of the language that the string should be translated to. The `from` parameter is the language code of the language that the string is written in. If the `from` parameter is not provided, the function will try to detect the language of the string. The `ttl` is used to set the time that the cache will be stored for. It defaults to 1 day.

The function can be used like this:

```
translate('Hello world!', 'fr'); // returns 'Bonjour le monde!'

translate('Hello world!', 'fr', 'en'); // returns 'Bonjour le monde!'
```

### API

[](#api)

The package also exposes a few API endpoints that can be used to achieve the same results as the methods above.

- `GET /languages` - returns all available languages
- `GET /language/codes` - returns the language codes of all available languages
- `POST /detect-language` - returns the language code of the language that a string is written in
- `POST /translate` - returns a translated string

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

937d ago

Major Versions

v0.2.0 → v1.0.02023-10-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/29f0087f9948836fa74f20e6fff1fa69f1260019c38bdf5d836d5ad3aa666a68?d=identicon)[Zubs](/maintainers/Zubs)

---

Top Contributors

[![Zubs](https://avatars.githubusercontent.com/u/53227444?v=4)](https://github.com/Zubs "Zubs (14 commits)")

### Embed Badge

![Health badge](/badges/zubs-translator/health.svg)

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

###  Alternatives

[vemcogroup/laravel-translation

Translation package for Laravel to scan for localisations and up/download to poeditor

135304.0k2](/packages/vemcogroup-laravel-translation)[mage-os/module-automatic-translation

Automatic AI content translation for Mage-OS.

277.1k](/packages/mage-os-module-automatic-translation)[acclaro/translations

Easily launch and manage multilingual Craft websites without having to copy/paste content or manually track updates.

1229.5k](/packages/acclaro-translations)

PHPackages © 2026

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