dqvzfp6468 2018-07-16 10:44
浏览 28

对语言文件中的数据进行排序

I want to have translations for a number of languages coming from the default Language files (as provided by CI). I'd also like to do some sorting on these values (e.g. to insert them in a dropdown list, I want them to be alphabetically sorted).

I have a project running in CodeIgniter and am in the process of moving all hardcoded text to the language files. This also includes some database tables.

For example, I have the following table:

+-------------+---------------------+--------------------+---------------+
| language_id |     language_nl     |    language_en     | language_code |
+-------------+---------------------+--------------------+---------------+
|           1 | Afrikaans           | Afrikaans          | AF            |
|           2 | Albanese            | Albanian           | SQ            |
|           3 | Arabisch            | Arabic             | AR            |
|           4 | Armeens             | Armenian           | HY            |
|           5 | baskisch            | Basque             | EU            |
|           6 | Bengalees           | Bengali            | BN            |
|             |                     |                    |               |
+-------------+---------------------+--------------------+---------------+

Now I would like to transfer this table to my language file. I will first start by deleting the language_nl and language_en columns. A new column will have to be introduced as well, language_key. So it should look like this:

+-------------+--------------+---------------+
| language_id | language_key | language_code |
+-------------+--------------+---------------+
|           1 | language_af  | AF            |
|           2 | language_sq  | SQ            |
|           3 | language_ar  | AR            |
|           4 | language_hy  | HY            |
|           5 | language_eu  | EU            |
|           6 | language_bn  | BN            |
+-------------+--------------+---------------+

Then in my language file I will add the following lines:

$lang["language_af"] = "African";
$lang["language_sq"] = "Albanian";
$lang["language_ar"] = "Arabic";

And so on...

I will then create a manager class to help me in finding the translations for each necessary language for the key. It would look something like this:

public function getLanguageName($key) {
   return lang(key);
}

Now I have two main questions:

1) Is this a good way of approaching the issue I have?

2) Let's say I need the languages to be shown in a drop-down. I want this dropdown to be alphabetically sorted (order will be different based on the language selected, of course). How do I approach this issue? Do I load in all the values from the language file, put them in an array and then sort that array?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line