trinityrank/multilanguage 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

trinityrank/multilanguage

Composer 安装命令:

composer require trinityrank/multilanguage

包简介

Add alternate multilanguage tags for same pages but on other language

README 文档

README

Latest Version on Packagist Total Downloads

Add alternate multilanguage tags for same pages but on other language.

Installation

Step 1: Install package

To get started with Laravel Multilanguage, use Composer command to add the package to your composer.json project's dependencies:

For Frontend and backend

    composer require trinityrank/multilanguage

Only for backend we need this package too

    composer require epartment/nova-dependency-container

Laravel Nova admin - Backend part

Step 2: Database

  • You need to publish migration from package
    php artisan vendor:publish --provider="Trinityrank\Multilanguage\MultilanguageServiceProvider" --tag="multilanguage-migration"
  • And then you need to run migration for alltenant(s)
    php artisan tenant:artisan "migrate"
  • Or only for one speciffic tenant
    php artisan tenant:artisan "migrate" --tenant=[--TENANT-ID--]

Step 3: Update database with default language

  • Update database field "multilang_language" to default language for your website
    UPDATE `articles` SET `multilang_language`='us' WHERE 1;
    UPDATE `pages` SET `multilang_language`='us' WHERE 1;
    UPDATE `categories` SET `multilang_language`='us' WHERE 1;
    UPDATE `static_pages` SET `multilang_language`='us' WHERE 1;

Step 4: Add field

  • Add field to your (Operater) resource into "fields" method
    use Trinityrank\Multilanguage\MultilanguagePanel;
    
    ...
    
    MultilanguagePanel::make()
  • Or if you use conditional fields than just add this into "fields" method
    // use "$this" or "self::", depends of resource structure
    $this->getMultilanguagePanel('Multilanguage', 'multilanguage')
  • Fields where category depends on language select
    // use "$this" or "self::", depends of resource structure
    // $this->getMultilanguageCategory("Language", [Resource::class, Model::class, ['rules']]),
    // example:
    $this->getMultilanguageCategory("Language", [ReviewPageCategory::class, TypesReviewPageCategory::class, ['required']]),

Step 5: If you are using conditional fields

Add this in tenant-default config

    'conditional_fields' => [
        ...

        '{{your_page_type_name}}' => [
            'categories' => [
                'visible' => true,
                'rules' => ['required', 'min:1', 'max:1', ... ]
            ],
        ]

        ...
    ]

Add this in tenant-{{tenant name}} config

    'conditional_fields' => [
        ...

        '{{your_page_type_name}}' => [
            'language' => [
                'visible' => true
            ],
            'categories' => [
                'visible' => true,
                'visibility' => ['onlyOnIndex'],
                'rules' => ['required', 'min:1', 'max:1']
            ],
        ]

        ...
    ]

Step 6: Add languages

In your "config\app.php" add multilanguage locales (use ISO language codes). For example:

    'locales' => [
        "us" => "USA",
        "uk" => "Great Britain",
        "ca" => "Canada",
        "au" => "Australia",
        "de" => "German",
        "at" => "Austria",
    ],

Frontend part

Step 7: Frontend part

Add helper function to "composer.json" file

        "autoload": {
            "files": [
                "vendor/trinityrank/multilanguage/src/Frontend/helpers.php"
            ],
            ...
        } 

And then run:

    composer dump-autoload

And change default "route()" method to "multilang_route()"

Step 8: Add languages

In your "config\app.php" add multilanguage locales (use ISO language codes). For example:

    'locales' => ['us', 'uk', 'ca', 'au', 'de', 'at'],

Step 9: Add hreflang metatags

  • For hreflang metatags add this to yout master.blade file in head tag
    <!-- Multilanguage alternate link tags -->
    {!! Trinityrank\Multilanguage\Frontend\HreflangDisplay::meta_tags($item) !!}
  • At the bottom of app.php add this part of code and change values according to the website settings
    // Url structure scheme (same as multicore tenant config file)
    'services' => [
        'deals' => false,
        'MoneyPage' => [
            'include_category_in_url' => false,
            'slug' => 'best',
        ],
        'News' => [
            'include_category_in_url' => false,
            'slug' => 'news',
        ],
        'Blog' => [
            'include_category_in_url' => false,
            'slug' => false,
        ],
        'ReviewPage' => [
            'include_category_in_url' => false,
            'slug' => 'reviews',
        ]
    ],

统计信息

  • 总下载量: 216
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固