Latest News
Đẩy log exception của spring boot lên elasticsearch
  • About
  • EmEditor
  • Register Google Adsense

Love Coding

Note anything I want

  • Home
  • Web Development
    • HTML
    • Javascript
    • jQuery
    • CSS
    • PHP
    • ASP
    • JSP
    • Fix Bug
  • Other Development
    • Desktop Java
    • Mobile J2ME
    • VBS
  • Operating System
    • Windows
    • Linux
  • Database
    • MySQL
    • Oracle
  • Software
Home » Yii2 » Love Coding: Yii2 sourceLanguage trong đa ngôn ngữ

Yii2 sourceLanguage trong đa ngôn ngữ

HuyPV
Add Comment
Yii2
Tuesday, October 4, 2016
$config['components'] = [
    'i18n' => [
        'translations' => [
            'hihi*' => [#category bắt đầu với hihi
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => 'E:/haha',#@app/messages
                #'sourceLanguage' => 'en-US',#mặc định là en-US nếu không khai báo
                'fileMap' => [
                    'hihi' => '01.php',#Yii::t('hihi', 'hello')
                    'hihi/error' => 'abcxyz.php',##Yii::t('hihi/error', 'hello')
                ],
            ],
        ],
    ],
    # Ví dụ language là vi-VN Yii2 sẽ quét file theo thứ tự ưu tiên sau để dịch
    # E:/haha/vi-VN/01.php => E:/haha/vi/01.php
    # Nếu language là vi-VN mà sourceLanguage là vi-VN thì Yii2 sẽ ko tìm file để dịch
 ];


Bonus:
Đã viết code Yii::t ở rất nhiều file rồi, giờ muốn extract các cụm từ đó ra 1 file để dịch sang ngôn ngữ khác thì làm thế nào?

Yii có công cụ dòng lệnh để extract ra cho bạn dịch các cụm từ sang ngôn ngữ khác 1 cách dễ dàng mà ko sợ bị bỏ thiếu:
Yii2 provides already somthing to help you with this topic. You can use the console with two yii commands:
messages/config: With the first command you create a configuration file
messages/extract: and with the second you extract the Yii:t() messages based on the configuration file
By default (part of the configuration file) all messages will be saved into a @app/messages directory that you have to have created before. These files will contain the required php arrays with empty string values for the translations. The files will be named by category that are used in the Yii::t('category', 'message') commands and are placed into sub directories for the specified language codes.

Tweet
Yii2 sourceLanguage trong đa ngôn ngữ Title: Yii2 sourceLanguage trong đa ngôn ngữ
Description: $config['components'] = [     'i18n' => [         'translations' => [             'hihi*' => [#... ...
Rating: 4

No comments :

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments ( Atom )
Quảng cáo

Popular Posts

  • VBS - Upload file HTTP Post
    Source: http://www.ericphelps.com/scripting/samples/Reference/Web/HTTP_POST.txt   Sub Upload(strUploadUrl, strFilePath, strFileField, strD...
  • Add other collapse div to your forum
    Collapse <div style="height: 16px; padding-right: 4px; font-weight: bold;" class="blockhead"> <span style=...
  • Use the YouTube API with PHP
    Process and integrate data from YouTube into your PHP application with PHP's SimpleXML extension Summary:   The YouTube vide...
  • Check Laravel version
    Đối tác bảo đang code và dùng Laravel, giờ muốn biết version Laravel tương ứng là bao nhiêu để xem mà code theo. Làm sao check? Cách 1: Sử...
  • Hàm chuyển từ ngày dương lịch sang âm lịch (PHP)
    <?php function INT($d) {     return floor($d); } function jdFromDate($dd, $mm, $yy) {     $a = INT((14 - $mm) / 12);     $y = $yy + 4800 ...
  • Trong laravel thì queue:work với queue:listen khác nhau thế nào?
    Trong laravel thì queue:work với queue:listen đều chạy jobs trong queue. Vậy 2 cái này cũng phải có gì đó khác nhau chứ, nếu ko thì nó là ...
  • Character Set và Collation trong MySQL là gì? Tạo DB thì để UTF8_GENERAL_CI hay UTF8_BIN
    Character Set là một tập các ký tự và dạng số hóa của các ký tự đó Collation là một tập các luật để so sánh các xâu được sinh ra từ các ký ...
  • git checkout file from other branch
    Đang làm trên nhánh dev. Muốn lấy 1 file, ví dụ: xxx/helper.php ở trên nhánh master về dev thì làm thế nào? Cách 1: nông dân nhiều bước nh...
  • mysql_error: Undeclared variable: INF
    mysql_error: Undeclared variable: INF PHP Code: $limit = 10; $page = isset($_GET['p']) ? $_GET['p'] : 1; $offset = ($pa...
  • Download media files (video, audio) from VnExpress.Net
    Download media files (video, audio) from VnExpress.Net Example: http://vnexpress.net/GL/Vi-tinh/Giai-tri/2010/02/3BA18A0E/page_4.asp htt...
Back to top!
Copyright 2010 Love Coding - All Rights Reserved Design by Newbie_PC - Powered by Blogger