[Share Experiences] transhell——一个让bash脚本可以国际化的方案
Tofloor
poster avatar
神末shenmo
Moderator
Spark-App
2023-01-27 10:07
Author

https://gitee.com/spark-community-works-collections/transhell

transhell

transhell 是一个bash国际化方案,可以让你的bash脚本拥有国际化的能力

为了使用transhell,请在你的脚本的最上方加入 example中的 .load_transhell 函数并执行之。

使用指南

建议结合本仓库example目录下的例子查看

  1. 将需要国际化的脚本中的文案转为助记变量(推荐为$TRANSHELL_CONTENCT_XXXXXX)

原文:

echo "这是一个测试文档"

修改后

echo “${TRANSHELL_CONTENT_THIS_IS_A_TEST_DOC}”
  1. 在脚本同位置下新建 transhell目录,并在其中放置翻译文件

命名为:脚本文件名_语言代码.transhell

例如 transhell/test_en_US.transhell或者 transhell/test_zh_CN.transhell

TRANSHELL_CONTENT_THIS_IS_A_TEST_DOC="这是一个测试文档"

特性

  1. load_translate会优先尝试加载 en_US语言的翻译文件,随后尝试用运行环境的语言的翻译文件来覆盖。这个特性可以保证在缺失全部或部分翻译条目的时候使用英文来fallback.如果你不希望使用英文作为fallback,请更改脚本中的加载顺序
  2. 除了在脚本所在目录,load_transhell还会尝试从 /usr/share/脚本文件名/transhell下读取。优先级为:脚本所在目录>/usr/share下。

目前还仅仅是实现了功能,后续会加入类似Qt语言家的辅助工具

Reply Favorite View the author
All Replies
柚子
deepin
2023-01-27 10:10
#1

like like like

Reply View the author
pzm9012
Moderator
2023-01-27 18:30
#2

大佬注意休息,凌晨还在工作。

Reply View the author
hanzn-zzx
deepin
2023-01-27 20:28
#3

kissing_heart like

Reply View the author
神末shenmo
Moderator
Spark-App
2023-01-27 20:50
#4

效果如下:

图片.png

图片.png

图片.png

Reply View the author
153******11
deepin
2023-01-27 23:52
#5

先服务好全球1/5的市场

Reply View the author
Amber
deepin
2023-01-28 00:41
#6

不说了,非常nb,我高攀不起like

Reply View the author
zccrs
deepin
2023-01-28 17:58
#7

创意不错,6666666666

Reply View the author