如何获取 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

到 return 这些文件中的数组:

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

print_r($arrays);