laravel-translatable | Translate your Eloquent models into different languages | Translation library

 by   nevadskiy PHP Version: 0.8.1 License: MIT

kandi X-RAY | laravel-translatable Summary

kandi X-RAY | laravel-translatable Summary

laravel-translatable is a PHP library typically used in Utilities, Translation, Laravel applications. laravel-translatable has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

The package provides possibility to translate your Eloquent models into different languages using a single database table.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              laravel-translatable has a low active ecosystem.
              It has 15 star(s) with 3 fork(s). There are 1 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 3 open issues and 14 have been closed. On average issues are closed in 72 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of laravel-translatable is 0.8.1

            kandi-Quality Quality

              laravel-translatable has no bugs reported.

            kandi-Security Security

              laravel-translatable has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              laravel-translatable is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              laravel-translatable releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed laravel-translatable and discovered the below as its top functions. This is intended to give you an instant insight into laravel-translatable implemented functionality, and help decide if they suit your requirements.
            • Resolve route binding .
            • Query scope to restrict the query to only translations .
            • Get attribute translation .
            • Create translations .
            • Applies the relation to the query .
            • Add translation .
            • Archive translation .
            • Remove unused translations .
            • Boot events .
            • Disable migrations .
            Get all kandi verified functions for this library.

            laravel-translatable Key Features

            No Key Features are available at this moment for laravel-translatable.

            laravel-translatable Examples and Code Snippets

            Laravel Translatable, Documentation
            PHPdot img1Lines of Code : 131dot img1License : Permissive (MIT)
            copy iconCopy
            $book = Book::where('title', 'Book about birds')->first();
            
            app()->setLocale('ru');
            
            $book->update(['title' => 'Книга о птицах']);
            
            echo $book->title; // 'Книга о птицах'
            
            app()->setLocale('en');
            
            echo $book->title; // 'Book abou  
            Laravel Translatable, Making models translatable
            PHPdot img2Lines of Code : 36dot img2License : Permissive (MIT)
            copy iconCopy
            /**
             * The attributes that can be translatable.
             *
             * @var array
             */
            protected $translatable = [
                'title',
                'description',
            ];
            
              
            Laravel Translatable,️ Demo
            PHPdot img3Lines of Code : 13dot img3License : Permissive (MIT)
            copy iconCopy
            $book = Book::create(['title' => 'Book about giraffes']);
            
            // Storing translations
            app()->setLocale('es');
            $book->title = 'Libro sobre jirafas';
            $book->save();
            
            // Reading translations
            app()->setLocale('es');
            echo $book->title; // '  

            Community Discussions

            QUESTION

            Laravel-scout : ElasticSearch with Translatable Entities (astrotomic/laravel-translatable)
            Asked 2021-Feb-25 at 23:51

            I'm trying to use "babenkoivan/scout-elasticsearch-driver" with "astrotomic/laravel-translatable", but i don't understand how I could index the translated words.

            My Model looks like :

            ...

            ANSWER

            Answered 2021-Feb-25 at 23:50

            I found a solution with the override of the method public function toSearchableArray() with something like:

            Source https://stackoverflow.com/questions/66348404

            QUESTION

            spatie / laravel-translatable shows the default locale when I try to retrieve the translation that does not exist yet
            Asked 2020-Dec-11 at 14:28

            The problem is that I want a title with 3 languages (English, Italian, German). The user can add 3 titles on a form for each language which only the Italian is required. After that the titles are saved in db like this using spatie / laravel-translatable:

            ...

            ANSWER

            Answered 2020-Dec-11 at 14:28

            Can you try to $useFallbackLocale=false param for not getting default locale string.

            You can check method usage from source code.

            As: $product->getTranslation('description_locale', 'de', false)

            Source https://stackoverflow.com/questions/65252615

            QUESTION

            Can't update a translatable model in Laravel
            Asked 2020-Oct-04 at 12:09

            I am using https://github.com/Astrotomic/laravel-translatable to make my models translatable.

            While I am trying to update the model using below method to update the mode along with its associated translated content.

            ...

            ANSWER

            Answered 2020-Oct-04 at 12:09

            I figured out that The issue was in the setup of the productTranslation model.

            the 'product_translations' table primary key is a composite of 'product_uuid' and the 'locale'.

            so in the 'ProductTranslation' model I defined the primary key as an array

            Source https://stackoverflow.com/questions/64184320

            QUESTION

            How can I implement I18n as a JSON object for a JPA or Hibernate entity?
            Asked 2020-Sep-16 at 16:20

            I have a Spring-boot application that uses JPA and Hibernate. You can find the whole code on this GitHub repository.

            My question is how can I add internationalization functionality to a specific column without any foreign keys and by using JSON structure?

            For example I would like to define a JPA entity like this:

            ...

            ANSWER

            Answered 2020-Jun-23 at 10:09

            Since this is a very common requirement, this answer is based on this article I wrote on my blog, which explains how the Hibernate Types project adds support for mapping Map entity attributes as JSON column types.

            Hibernate Types project

            First, you need to add the Hibernate Type project dependency.

            Afterward, you could use either an HStore column or a JSONB column to store the locate-specific titles:

            Source https://stackoverflow.com/questions/62409871

            QUESTION

            How can I executing query to only one?
            Asked 2020-Jul-09 at 10:58

            Here's the story, I'm using this package (laravel-translatable) for model Translations.

            I used it for the governorates in select box and every thing is good and works, BUT when I open the debugger I found there is 21 queries run!!

            There is 1+N issue, How can I executing to one query!

            just for info:

            There is two models for translate ( Governorate, GovernorateTranslation ) first one contains just (id) and the second contains ( id , local , name, governorate_id).

            ...

            ANSWER

            Answered 2020-Jun-26 at 19:08

            you can try to call all ids in just one query

            Some ways to do this

            Source https://stackoverflow.com/questions/62601060

            QUESTION

            Composer won't install even though there's no apparent conflict
            Asked 2020-May-10 at 13:02

            I've been struggling with this issue for a while. I'm upgrading from Laravel 6 to 7, and composer is not cooperating here. It outputs an enormous dependency story which doesn't make any sense to me at all.

            I made sure my dependencies support Laravel 7.0, and I might've missed something, but composer is surely not highlighting it if I did.

            I removed composer.lock and vendor as well.

            Here's my composer.json:

            ...

            ANSWER

            Answered 2020-May-10 at 13:02

            At the end of the conclusion list, it tells you it wants to install php-tmdb/api: 2.1.x-dev.

            If you go to that project's repo, you'll notice there's a v3 available.

            v2 of php-tmdb/api wants "symfony/event-dispatcher": ">=2.4,<5" - that collides with laravel's constraint.

            Solution: require php-tmdb/api: 3.0

            https://github.com/php-tmdb/api/releases

            Source https://stackoverflow.com/questions/61711589

            QUESTION

            Laravel 7 ignore global scope when creating
            Asked 2020-Apr-25 at 22:08

            I have a model Publisher that has a many to many relationship to Collection

            Both have a property called approved that is set to false when initially created

            I have a global scope that hides any Publisher or Collection where approved === false

            ...

            ANSWER

            Answered 2020-Apr-25 at 22:08

            After careful investigation and some help, it came to light this was the result of the koenhoeijmakers/laravel-translatable package on the Collection

            I have solved the issue by not applying the middleware that applies the ApprovedScope on the store routes where this was causing issues.

            Source https://stackoverflow.com/questions/61384691

            QUESTION

            Laravel 6 groupBy to belongsTo relationship
            Asked 2019-Dec-29 at 17:41

            Hello I have Post model with relation:

            ...

            ANSWER

            Answered 2019-Dec-29 at 17:06

            QUESTION

            Unknown Reason for App Locale Encrypted During Render?
            Asked 2019-Oct-22 at 01:57

            I am having an unusual issue.

            I have a multi tenant Laravel app that uses app()->setLocale() for setting the default locale for the tenant

            When I get the locale in the view/controller for any tenant or the root app I get a encrypted string like this: eyJpdiI6ImtMdFI5Q05KSkU0WlJGaG9HUnF4K2c9PSIsInZhbHVlIjoic3ZVXC90SzVRRjBhUkpQdHJmcHNDUlE9PSIsIm1hYyI6IjE3MDQ4MjBiYTg0YzgwMWRmZmZlMTYxN2EwNDkwODE2MGJmZTNmNDJjOTAwYmE0ZGVlOWY0Yjc4YjIyNmEyMTAifQ==

            but if I get it from the AppServiceProvider just after I set it I the correct result like: en_AU

            My composer.json:

            ...

            ANSWER

            Answered 2019-Oct-22 at 01:57

            Ok So it turns out the issue is with a middleware that I created to save the users language option to a cookie value.

            The problem was that if one did not exist I set the language to false and hence the long string.

            The Middleware would then grab this value each time the user loaded the page.

            Source https://stackoverflow.com/questions/58481173

            QUESTION

            How to translate string as parameter in laravel blade while using include
            Asked 2019-Oct-10 at 15:41

            I'm trying to translate a string on my blade that is a parameter being sended on a include:

            ...

            ANSWER

            Answered 2019-Oct-10 at 14:00

            __() should work

            Make sure to clear views cache when you change them if they don't refresh automatically

            Source https://stackoverflow.com/questions/58324626

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install laravel-translatable

            Install a package via composer.
            Optional. If you are not going to use translations for models with UUID primary keys, make the following:
            Publish package migration
            Replace the line $table->uuidMorphs('translatable'); with $table->morphs('translatable'); in the published migration.
            Run the migration command.

            Support

            Default locale values are stored in the original table as usual. Values in non-default locales of each translatable model are stored in the single translations table. The package takes the default locale from the config('app.fallback_locale') value. Note that translatable models will always be created in default locale even when the current locale is different. Any translations can be attached only to existing models. The package automatically eager loads translations of the current locale for you, so you can easily retrieve collection of models as usual. The package automatically remove translations of deleted models respecting softDeletes, but if translatable models have been removed using query builder, their translations will exist in the database. To manually remove all unused translations, run the php artisan translatable:remove-unused command. Sometimes you may need to query translatable model without the translations relation. You can do this using withoutTranslations scope. You can execute queries on translatable models by translatable attributes. It will also work with values in default locale. If you want to query rows only by a specific locale, you should pass it by yourself. $books = Book::whereTranslatable('title', 'Книга о жирафах', 'ru')->get();. Otherwise, the query builder will return matched rows within all available locales. Also, you can use different operators for querying translations. Ordering models by a translatable attribute in the current locale. Ordering models by a translatable attribute in the specific locale. For more complex queries - feel free to use Laravel relation queries. If you do not want to automatically load or save translations when you interact with a translatable property, you can disable the feature. To disable it for a specific model, override the autoLoadTranslations or autoSaveTranslations methods in your model like so. Or globally for every model.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/nevadskiy/laravel-translatable.git

          • CLI

            gh repo clone nevadskiy/laravel-translatable

          • sshUrl

            git@github.com:nevadskiy/laravel-translatable.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link