All Projects → DxCat → translatable

DxCat / translatable

Licence: MIT license
Add multilingual support to your laravel 5 models

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to translatable

weel-translate
🚦 后续更新发布到 Releases 不再提交 AMO 扩展市场
Stars: ✭ 57 (+67.65%)
Mutual labels:  translate
Translator3000
Automatic translator of games made on Ren'Py engine.
Stars: ✭ 78 (+129.41%)
Mutual labels:  translate
TranslationPlugin
Translation plugin for IntelliJ based IDEs/Android Studio/HUAWEI DevEco Studio.
Stars: ✭ 9,375 (+27473.53%)
Mutual labels:  translate
ngx-translate-lint
Simple CLI tools for check `ngx-translate` keys
Stars: ✭ 25 (-26.47%)
Mutual labels:  translate
sketch-crowdin
Connect your Sketch and Crowdin projects together
Stars: ✭ 35 (+2.94%)
Mutual labels:  translate
kictor
A dictionary based on the console, 一个基于控制台的词典工具
Stars: ✭ 15 (-55.88%)
Mutual labels:  translate
learnrxjs
Русскоязычная документация RxJS
Stars: ✭ 20 (-41.18%)
Mutual labels:  translate
EzLocalization
Localize your flutter application quickly and easily.
Stars: ✭ 13 (-61.76%)
Mutual labels:  translate
php-google-translate-for-free
Library for free use Google Translator. With attempts connecting on failure and array support.
Stars: ✭ 124 (+264.71%)
Mutual labels:  translate
gpytranslate
A Python3 library for translating text using Google Translate API.
Stars: ✭ 34 (+0%)
Mutual labels:  translate
detect-browser-language
Detect browser language
Stars: ✭ 35 (+2.94%)
Mutual labels:  translate
FastNN
FastNN provides distributed training examples that use EPL.
Stars: ✭ 79 (+132.35%)
Mutual labels:  models
mlx
Machine Learning eXchange (MLX). Data and AI Assets Catalog and Execution Engine
Stars: ✭ 132 (+288.24%)
Mutual labels:  models
TeslaKit
Elegant Tesla API in Swift
Stars: ✭ 47 (+38.24%)
Mutual labels:  models
psyplot
Python package for interactive data visualization
Stars: ✭ 64 (+88.24%)
Mutual labels:  models
googletranslate
Python Google Translate (using reverse-engineered public API, so free)
Stars: ✭ 67 (+97.06%)
Mutual labels:  translate
zTranslate
zTranslate是pascal/c++圈的国际化之手,可以一键国际化,也可以用最廉价外包投入解决项目国际化问题
Stars: ✭ 29 (-14.71%)
Mutual labels:  translate
django-jsonfield-backport
Backport of the cross-DB JSONField model and form fields from Django 3.1.
Stars: ✭ 36 (+5.88%)
Mutual labels:  models
node-google-translate-skidz
Simple Node.js library for talking to Google's Translate API for free.
Stars: ✭ 70 (+105.88%)
Mutual labels:  translate
DynamicalBilliards.jl
An easy-to-use, modular, extendable and absurdly fast Julia package for dynamical billiards in two dimensions.
Stars: ✭ 97 (+185.29%)
Mutual labels:  models

Package Archived and Abandoned

This package is abandoned and no longer maintained. This package no longer have much value for the open source community and it is severely outdated. I'm sorry for any inconveniences caused.

Laravel 5 Translatable

A simple package that makes it really easy for you to create models with translations. Laravel already provides a really nice way to support multilingual strings in the blade files, however it is lacking the mean to allow for translations on database entries which is what this package is trying to achieve, elegantly.

Highlights

  • Super simple to use. Really, just use the trait on your models, and you're good to go!
  • Only a single table will be needed to store the translations of all of your models. And you can define this table name in the config too!

Installation

  1. Include this package via composer.
$ composer require askaoru/translatable
  1. Add the service provider to your config/app.php under the providers array.
'providers' => [
    // Other laravel packages ...
    
    Askaoru\Translatable\TranslatableServiceProvider::class,
],
  1. Publish the config and migration files.
$ php artisan vendor:publish --provider="Askaoru\Translatable\TranslatableServiceProvider"
  • Doing so will create 2 files which you can edit if you want to change the database name
config\translatable.php
database\migrations\2017_07_01_031473_create_model_translations_table.php
  1. Finally run the migration.
$ php artisan migrate

Setting up

To use this package on your project, all you need to do is inherit the translatable trait in your model. Like for an example, a Post model which you'd like to have multilanguage support for.

<?php

namespace App;

use Askaoru\Translatable\Traits\Translatable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Translatable;
    
    //
}

Usage

Basically, there's only 3 main methods that you would ever need for this package, set(), get() and clear().

  1. The set() method. This method is the how you would set your translations. It's very versatile as you can use it to set a single or multiple languages at the same time. It is also a 'save or update' kind of things which mean that if you're trying to set a translation to something that has been defined before, it would update that. But if it was never defined, it will create the record instead.

The third parameter would be which language you're setting the translation for, but if you does not define it, it will use laravel's default language that are set at the moment.

    # Example
    // Fetch the post with an ID of 1.
    $post = Post::find(1);
    
    // Set the post title to 'Hello World' in the default language (assuming the default / current language is English).
    $post->translation()->set('title', 'Hello World');
    
    // Set the post title to 'こんにちは世界' in the japanese locale.
    $post->translation()->set('title', 'こんにちは世界', 'jp');
    
    // Set the post title to multiple locales at the same time.
    $post->translation()->set('title', [
        'en' => 'Hello World',
        'jp' => 'こんにちは世界'
    ]);
  1. The get() method. This simple method is how you fetch the translation that you have set.
    # Example
    // Again, fetch the model that this translation trait is attached to, in this case, Post.
    $post = Post::find(1);
    
    // Get the title in current / default language.
    $post->translation()->get('title'); // Would return 'Hello World' again assuming default is English.
    
    // Get the title in other language, in this example, Japanese.
    $post->translation()->get('title', 'jp'); // Would return 'こんにちは世界'.
    

    # There's also a getAll() method to make it easier for you fetch multiple translations at one time.
    // Get title for all languages.
    $post->translation()->getAll('title'); // Would return ['en' => 'Title', 'jp' => 'こんにちは世界', 'ar' => 'مرحبا بالعالم']
    
    // Get titles for specific languages.
    $post->translation()->getAll('title', ['en', 'ar']); // Would return ['en' => 'Title', 'ar' => 'بالعالم']
  1. The clear() method. Well this is just as you would imagine. It would clear the translation that was set. This method will return true if deletion is successful and will return false if the translation doesn't exist.
    # Example .. Seriously making documentations is tiring but a good documentation is important to have...
    // Fetch the post.
    $post = Post::find(1);
    
    // Clear the translation for the post title of current / default language, English.
    $post->translation()->clear('title');
    
    // Clear the translation for the post title of the Japanese language.
    $post->translation()->clear('title', 'jp');
    
    # There's also a clearAll() method to make it easier for you clear multiple translations at one time.
    // Clear all translations for post title.
    $post->translation()->clearAll('title'); // Would return number of deleted rows
    
    // Clear the translation for post title in specific languages.
    $post->translation()->clearAll('title', ['en', 'jp']); // Would remove translations for English and Japanese

Contributions

Every pull request and contributions to improve this package would be very, very much appreciated. And if you have any question, found a bug, or need any help related to this package, please do open an issue. I will do my best to attend to them.

List of all contributors

That's it, I hope this little package would be helpful to you. Thanks for giving it a try!

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].