Download the PHP package wazza/dom-translate without Composer

On this page you can find all versions of the php package wazza/dom-translate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dom-translate

Version Tests Laravel PHP License Issues Buy me a coffee

Laravel Translate Package

A Laravel package that uses Blade directives to provide real-time translations for any phrase in your views — backed by a smart caching layer (session → database → cloud API) to minimise API calls and costs.

Write your Blade templates in English, serve every visitor in their own language — automatically.


Table of Contents


How it Works

Three database tables (domt_languages, domt_phrases, domt_translations) power a three-level cache:

  1. Session (fastest) — if DOM_TRANSLATE_USE_SESSION=true, translations are stored in the user's session after the first retrieval.
  2. Database (fast) — if DOM_TRANSLATE_USE_DATABASE=true (default), translations are stored and retrieved from the DB. Each phrase is hashed (SHA-256 HMAC) and stored in an indexed column for sub-millisecond lookups.
  3. Cloud API (fallback) — only when no cached translation exists. The result is immediately stored in the DB (and session) to prevent future API calls.

Laravel caches compiled Blade views, so unchanged pages make zero database or API calls after the first render.


Requirements

Requirement Version
PHP ^8.2
Laravel ^12.0
GuzzleHTTP ^7.8 (auto-installed)
Cloud API key Google or Bing (at least one)

Installation

Publish the config and migrations, then run the migrations:

Add your API key(s) to .env:

Clear config cache:

Auto-discovery: The service provider is auto-discovered. No manual registration is needed in bootstrap/providers.php unless you have disabled package discovery.


Configuration

After publishing, the config file is at config/dom_translate.php. All settings are also controllable via .env:

Security note: Change DOM_TRANSLATE_HASH_SALT to a unique value per application. Do not reuse the default across projects.


Translation Providers

Google Cloud Translation Setup

  1. Visit Google Cloud Console and create a project.
  2. Enable Cloud Translation API under APIs & Services → Library.
  3. Create an API key under APIs & Services → Credentials.
  4. Restrict the key to Cloud Translation API to limit exposure.
  5. Add to .env:

Free tier: 500,000 characters/month. Billing account required even for free tier.

Test with curl:


Bing / Azure Cognitive Translator Setup

  1. Sign in to the Azure Portal.
  2. Create a Cognitive Services resource (or a dedicated Translator resource).
  3. Copy one of the subscription keys from Keys and Endpoint.
  4. Add to .env:

Free tier: 2,000,000 characters/month (F0 tier).


Blade Directives

@transl8(phrase[, dest[, src]])

The primary directive. Translates a phrase to the destination language.

Language-Specific Shortcuts

Pre-registered directives for common languages:

Adding more languages in your AppServiceProvider::register():

@transl8auto(phrase)

Translates to whatever language is stored in the user's session or cookie. See Auto-Translation below.


Auto-Translation (@transl8auto)

@transl8auto is the most powerful directive. It reads the user's language preference (set via a language switcher) and translates accordingly — no per-phrase language specification needed.

Language priority order

  1. Session — session('app_language_code')
  2. Cookie — cookie('app_language_code')
  3. Config default — dom_translate.language.dest
  4. App locale — config('app.locale')
  5. English — final fallback

Building a language switcher

1. Add a selector to your layout:

2. Wire it up with JavaScript:

Vue 3 Component Example


Language Preference API Routes

Enabled by default. Can be disabled with DOM_TRANSLATE_ROUTES_ENABLED=false.

POST /api/translate/set-language

Response:

Also sets a 1-year, httpOnly cookie with the preference.

GET /api/translate/get-language

Response:

Disable routes and roll your own


SetLocale Middleware

SetLocaleMiddleware automatically syncs Laravel's application locale — and Carbon's locale — to the user's language preference on every request.

This ensures __(), trans(), @lang, validation messages, and Carbon date formatting all use the same language as the translate directives.

Enabled by default. To disable:

To keep the middleware but not auto-apply it to the web group:

Then apply it manually where needed:


Using the Helper Directly

TranslateHelper and PhraseHelper are also available for use in controllers, jobs, or anywhere outside Blade:


Upgrading to v2.5

If you are upgrading from v2.4.x:

  1. Re-publish migrations — the migration files have been updated to anonymous class syntax (required by Laravel 12). If you have already run the old migrations, no action is needed for existing databases. For fresh installs, re-publish:

  2. No breaking changes — all Blade directives, config keys, and .env variables remain identical.

  3. BingTranslate is now implemented — if you set DOM_TRANSLATE_PROVIDER=bing in your .env, it will now work with the Azure Cognitive Translator v3 API.

  4. Cookie security — the language preference cookie is now httpOnly=true (XSS protection). This is transparent to your application.

  5. DOM_TRANSLATE_HASH_SALT — if you are using a custom salt, ensure it remains set in your .env to preserve existing hash lookups in the database.

Troubleshooting

E_STRICT deprecation warnings during composer install

This is not caused by this package. It is caused by an outdated system-level Composer installation (typically /usr/share/php/Composer/). Update your server's Composer:

Translations not showing / returning original phrase

  1. Check your API key is set: DOM_TRANSLATE_GOOGLE_KEY or DOM_TRANSLATE_BING_KEY.
  2. Check DOM_TRANSLATE_LOG_LEVEL=3 and review Laravel's log for API errors.
  3. Ensure the destination language code (DOM_TRANSLATE_LANG_DEST) exists in the domt_languages table.
  4. Clear config and view cache:

MissingAppKeyException in tests

Ensure APP_KEY is set in phpunit.xml or your .env.testing. The package's test suite sets a dummy key automatically for its own tests.

Language not persisting between requests

Ensure DOM_TRANSLATE_USE_SESSION=true or that cookies are being sent with requests. For AJAX requests, verify the X-CSRF-TOKEN header is included in POST calls.


Contributing

Contributions are welcome. Please read SECURITY.md.


Made with ☕ by Warren Coetzee


All versions of dom-translate with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
guzzlehttp/guzzle Version ^7.8
illuminate/support Version ^12.0
php Version ^8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wazza/dom-translate contains the following files

Loading the files please wait ...