簡體   English   中英

如何獲取yii1中的所有語言數組?

[英]how to get all the languages array in yii1?

目錄結構是這樣的

modules/
       /module1
              /messages/
                       /en
                          /admin.php
                          /profile.php
                       /ru/
                          /admin.php
                          /profile.php

       /module2/
              /messages/
                       /en
                          /account.php
                          /stats.php
                       /ru
                          /account.php
                          /stats.php

每個php文件內部都有一個巨大的數組,其中數組包含文本字符串的鍵值對,例如

return array(
'hello' => 'aloha'
);

那么如何獲取每個文件中的數組?

您可以使用glob() php函數實現新方法來實現此目的

$language = 'en';

foreach (glob('modules/*/messages/' . $language . '/*') as $file) {
    echo "$file\n";
}

輸出:

modules/module1/messages/en/admin.php
modules/module1/messages/en/profile.php
modules/module2/messages/en/admin.php
modules/module2/messages/en/profile.php

從這些文件內部返回數組:

$language = 'en';
$arrays = [];
foreach (glob('modules/*/messages/' . $language . '/*') as $file) {
    $arrays[] = require_once "$file";
}

print_r($arrays);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM