Coder Social home page Coder Social logo

nhobi / multilingual-nova Goto Github PK

View Code? Open in Web Editor NEW

This project forked from digitalcloud/multilingual-nova

0.0 0.0 0.0 513 KB

๐Ÿ’ช Multilingual Nova (using default nova fields)

Vue 46.02% JavaScript 13.65% CSS 1.89% PHP 35.59% HTML 2.85%

multilingual-nova's Introduction

Multilingual Nova (using default nova fields)

This package allow you switch Nova language. Languages could be retrieved as array from config file or from database.

Installation

You can install the package via composer:

composer require digitalcloud/multilingual-nova

You can publish the config file:

php artisan vendor:publish --provider="Digitalcloud\MultilingualNova\FieldServiceProvider" --tag=config

This is the contents of the file which will be published at config/multilingual.php

<?php

return [

    /*
     * The source of supported locales on the application
     * Available selection "array", "database". Default array
     */
    'source' => 'array',

    /*
     * If you choose array selection, you should add all supported translation on it as "code" => "label"
     */
    'locales' => [
        'en' => 'English',
        'ar' => 'Arabic',
        'de' => 'Deutsch'
    ],

    /*
     * If you choose database selection, you should choose the model responsible for retrieving supported translations
     * And choose the 'code_field' for example "en","ar","ru"...
     * And choose the 'label_field' which will be show for users, for example "English","EN", ....
     */
    'database' => [
        'model' => 'App\\Language',
        'code_field' => 'code',
        'label_field' => 'label'
    ],

    /*
     * The view style you want to show on index & details page
     * Available selection "button", "list", "mix" default button
     */
    'style' => 'button',

    /*
     * If you choose mix selection, you can define after how many languages should button convert to list
     */
    'convert_to_list_after' => 3
];

Usage

Nova Language Tool

You can use it as a tool by registering it with Nova. This is typically done in the tools method of the NovaServiceProvider, in app/Providers/NovaServiceProvider.php.

use Digitalcloud\MultilingualNova\NovaLanguageTool;
// ....

public function tools()
{
    return [
        // ...
        new NovaLanguageTool(),
        // ...
    ];
}

Nova Language Field:

You can add Multilingual field to your resource.

    use Digitalcloud\MultilingualNova\Multilingual;
    
    // ....
    
    public function fields(Request $request)
    {
        return [
            // ...
            Multilingual::make('Language'),
            // ...
        ]
    }

Note: the field is a virtual field, and it's not required to be a database column. You can consider it as a language switcher input.

In index and detail page, the field will allow you to go to edit form with the selected language. In create and update page, the field allow you to change the language of inputs in the form in easy and direct way.

Defining Locales

You can set the source of locals in the config file. Posible options are array or database. In case your language source is array, you need to add allowed languages in the locales array in the config file. When your language source is database, you need to configure the eloquent model of the language table, the column of the language code and the column of the language label.

Alternatively you can override the config locales using setLocales(...) function:

    use Digitalcloud\MultilingualNova\Multilingual;
    
    // ....
    
    public function fields(Request $request)
    {
        return [
            // ...
            Multilingual::make('Language')->setLocales([
                  'ar' => 'Arabic',
                  'en' => 'English',
                  'de' => 'Deutsch',
            ]),
            // ...
        ]
    }

Displaying options

This tool allow you to switch between dispaling style of the language selector field. possible displaying options are button, list or mix. By default, the displaying style is button. If the field has a translation of a specific language, the button will be a blue one - primary button, ad if no translation available the button will be gray - default button.

If your application support many languages, this button displaying style is not suitable, so list displaying will be more suitable. With list displaying, locales are grouped in a dropdown list, allowing you to select an option from this list.

Other perfect option for displaying languages, is mix. It allow you to mix between button and list displaying options. For example, if the system supported less than three locales, then they will display as button otherwise list will be selected. This case can be achieved by setting the convert_to_list_after in the config file with 3 or what ever value you want.

Features

  • Display supported locales in the index view
  • Allow you to edit any resource in any supported locale
  • NO ADDITIONAL FIELDS, just use the default laravel form fields
  • Quick switch between languages in index, details, create and update pages
  • Support Relations fields and sub tables
  • Auto fill form fields with default/fallback language content
  • Display translated/untranslated status for each locale
  • List the supported locale using Config file

Roadmap

  • Display translated/untranslated status for each locale
  • List the supported locale using Config file
  • Manage the supported locale using Database resource
  • Autodetect translatable Models
  • Better support for untranslatable fields

Screenshots

Index page

Index languages buttons

Create/Update page

mmmm

Language Tool

multiligual tool

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.