All Projects → weglot → translate-laravel

weglot / translate-laravel

Licence: MIT license
Translate your Laravel website easily.

Programming Languages

PHP
23972 projects - #3 most used programming language
Blade
752 projects

Projects that are alternatives of or similar to translate-laravel

Laravel Js Localization
🌐 Convert your Laravel messages and consume them in the front-end!
Stars: ✭ 451 (+1152.78%)
Mutual labels:  i18n, laravel-package
react-router-i18n
Internationalization library built on top of React Router
Stars: ✭ 24 (-33.33%)
Mutual labels:  i18n
JSON-i18n-Editor
Translate your i18n JSONs for your website or app with this tool
Stars: ✭ 29 (-19.44%)
Mutual labels:  i18n
banana-i18n
banana-i18n - Javascript Internationalization library
Stars: ✭ 61 (+69.44%)
Mutual labels:  i18n
laravel-translate
Generate translation files for Laravel using Google Translate
Stars: ✭ 22 (-38.89%)
Mutual labels:  i18n
stone.js
gettext-like client-side Javascript Internationalization Library
Stars: ✭ 20 (-44.44%)
Mutual labels:  i18n
i18n-unused
The static analyze tool for finding, marking and removing unused and missing i18n translations in your JavaScript project
Stars: ✭ 76 (+111.11%)
Mutual labels:  i18n
nestjs-i18n
The i18n module for nestjs.
Stars: ✭ 376 (+944.44%)
Mutual labels:  i18n
vscode-flutter-i18n-json
VS Code extension to create a binding between your translations from .json files and your Flutter app.
Stars: ✭ 93 (+158.33%)
Mutual labels:  i18n
girlsfrontline-core
GirlsFrontline library
Stars: ✭ 21 (-41.67%)
Mutual labels:  i18n
babelfish
🐡 Straightforward library for translations and dictionaries
Stars: ✭ 47 (+30.56%)
Mutual labels:  i18n
translate-go
https://babyblue94520.github.io/translate-go/dist/
Stars: ✭ 14 (-61.11%)
Mutual labels:  i18n
artisan-remote
Artisan Remote is a package for Laravel to interact with your Artisan Commands via an HTTP API.
Stars: ✭ 69 (+91.67%)
Mutual labels:  laravel-package
menus
Laravel Enso main menu manager, for easy management of the application menus straight from the interface, whether that means adding, removing or reordering them
Stars: ✭ 15 (-58.33%)
Mutual labels:  laravel-package
laravel-login-links
Create (passwordless) login links for users
Stars: ✭ 13 (-63.89%)
Mutual labels:  laravel-package
i18n-testing
International data for testing and QA
Stars: ✭ 61 (+69.44%)
Mutual labels:  i18n
i18n
Yii i18n
Stars: ✭ 20 (-44.44%)
Mutual labels:  i18n
core
Core and Admin UI for Angular7+ web applications
Stars: ✭ 47 (+30.56%)
Mutual labels:  i18n
awesome-landlord
A simple, single database multi-tenancy solution for Laravel 5.2+
Stars: ✭ 41 (+13.89%)
Mutual labels:  laravel-package
vue-translated
Internationalization (i18n) and localization (l10n) library for Vue.js v2.
Stars: ✭ 19 (-47.22%)
Mutual labels:  i18n

⚠️ This package is deprecated ⚠️

Create a new project and use the subdomain integration (Technology: Other) to translate your Laravel website.


Laravel Package

WeglotSlack Latest Stable Version Maintainability License

Overview

Seamless integration of Weglot into your Laravel project.

Requirements

  • PHP version 5.5 and later
  • Laravel 5.*
  • Weglot API Key, starting at free level

Installation

You can install the library via Composer. Run the following command:

composer require weglot/translate-laravel

To use the library, use Composer's autoload:

require_once __DIR__. '/vendor/autoload.php';

Getting Started

Package Register

This package use auto-discovery, when you require it from composer, you should have nothing to do and Provider gonna be added automatically to your config/app.php providers list.

If this doesn't work, you can add our provider to the config/app.php, as following:

return [
    // ...

    'providers' => [
        // ... Other packages ...
        Weglot\Translate\TranslateServiceProvider::class
    ],

    // ...
];

Quick configuration

As usual for Laravel packages, you can publish configuration files by doing:

$ php artisan vendor:publish --provider="Weglot\Translate\TranslateServiceProvider" --tag="config"

You'll find the configuration file in config/weglot-translate.php with default values. If you want to go deeper in configuration, I suggest you to consult the corresponding part of this README.

Configuration

Here is a full configuration file:

<?php

return [
    'api_key' => env('WG_API_KEY'),
    'original_language' => config('app.locale', 'en'),
    'destination_languages' => [
        'fr'
    ],
    'exclude_blocks' => ['.site-name'],
    'exclude_urls' => ['\/admin\/.*'],
    'prefix_path' => '',
    'cache' => false,

    'laravel' => [
        'controller_namespace' => 'App\Http\Controllers',
        'routes_web' => 'routes/web.php'
    ]
];

This is an example of configuration, enter your own API key, your original language and destination languages that you want.

  • api_key : is your personal API key. You can get an API Key by signing up on Weglot.
  • original_language : original language is the language of your website before translation.
  • destination_languages : are the languages that you want your website to be translated into.
  • prefix_path : if your laravel installation is not on webroot (ie. something like that: https://my.website.com/foo/ is your actual root) set it to specify the path to your laravel installation
  • cache : if you wanna use cache or not. It's not a required field and set as false by default. Look at Caching part for more details.

There is also a non-required parameters:

  • exclude_blocks : where you can list all blocks you don't want to be translated. On this example, you can see that all blocks with the site-name class won't be translated.
  • exclude_urls : you can prevent urls path from being translated (such as an admin path in this example)

And some Laravel-related parameters:

  • laravel.controller_namespace : Used internaly when rewriting routes, change it if your Laravel namespace isn't App or your controllers are moved.
  • laravel.routes_web : Used internaly when rewriting routes, refer to the file where you have all your web routes.

Routing

Since we are adding routes for each destination languages we need a strong way to manipulate urls.

We choose to make that through named routes and route() helper.

When you create a route, you have to give a name as following:

Route::get('/', 'Controller@method')
    ->name('my_route_name');

Then you can use it in your blade templates as following:

<a href="{{ route('my_route_name') }}">My link</a>

Like that, we will detect current language and adjust url if needed.

Forcing language

You can force any language as following:

<a href="{{ route('my_route_name', ['_wg_lang' => 'es']) }}">My link</a>

Like that, it will force es language for this link !

Caching

We implemented usage of Cache Facade for our package.

If you wanna use cache, just put the cache parameter to true in this package configuration. It will plug onto the Laravel cache behavior.

If you wanna clear your translation cache, just use the weglot:cache:clear command as following:

$ php artisan weglot:cache:clear

Helper reference

weglotCurrentUrlInstance

One of the core helper of this plugin it returns an instance of Weglot\Util\Url which is what manages:

  • Detect current language
  • What are translated urls based on current url
  • Is a given url translable or not (based on excludedUrls option)
  • Generate hreflinks

Here is some usage examples:

$url = weglotCurrentUrlInstance();

// returns current language
$lang = $url->detectCurrentLanguage();

// returns all translated urls
$urls = $url->currentRequestAllUrls();
/**
 * Will return an array like this:
 * Array(
 *   'en' => 'https://weglot.com/',
 *   'fr' => 'https://weglot.com/fr',
 *   'es' => 'https://weglot.com/es',
 *   'de' => 'https://weglot.com/de'
 * )
 **/

// returns a boolean to know if the current url is translable
$translable = $url->isTranslable();

// returns string containing DOM with hreflang tags
$hreflangTags = $url->generateHrefLangsTags();
/**
 * Will return an array like this:
 * <link rel="alternate" href="https://weglot.com" hreflang="en"/>
 * <link rel="alternate" href="https://weglot.com/fr" hreflang="fr"/>
 * <link rel="alternate" href="https://weglot.com/es" hreflang="es"/>
 * <link rel="alternate" href="https://weglot.com/de" hreflang="de"/>
 **/

weglotButtonRender

You can add a language button with the helper function: weglotButtonRender

Two layouts exists:

<!-- first layout -->
{{ weglotButtonRender(1) }}

<!-- second layout -->
{{ weglotButtonRender(2) }}

If you want to overwrite theses templates you can publish them with the following artisan command:

$ php artisan vendor:publish --provider="Weglot\Translate\TranslateServiceProvider" --tag="views"

weglotHrefLangRender

Hreflang links are a way to describe your website and to tell webcrawlers (such as search engines) if this page is available in other languages. More details on Google post about hreflang: https://support.google.com/webmasters/answer/189077

You can add them through the helper function: weglotHrefLangRender

Just put the function at the end of your <head> tag:

<html>
    <head>
        ...

        {{ weglotHrefLangRender() }}
    </head>

weglotLanguage

Simple helper to convert ISO 639-1 code to full language name. It can takes one boolean parameter that allow you to choose having english name or original language name.

Here is a quick example:

$name = weglotLanguage('bg');
// $name will contains: "Bulgarian"

$name = weglotLanguage('bg', false);
// $name will contains: "български"

Examples

You'll find a short README with details about example on each repository:

About

translate-laravel is guided and supported by the Weglot Developer Team.

translate-laravel is maintained and funded by Weglot SAS. The names and logos for translate-laravel are trademarks of Weglot SAS.

License

The MIT License (MIT)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].