diff --git "a/\344\275\277\347\224\250\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242/\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242\345\237\272\346\234\254\347\224\250\346\263\225.md" "b/\344\275\277\347\224\250\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242/\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242\345\237\272\346\234\254\347\224\250\346\263\225.md" index 21d527bb02e9e54a75c7192b10e26127ee418a82..93406e3f040a248f397a4bbea3c94c1f48ee1e43 100644 --- "a/\344\275\277\347\224\250\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242/\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242\345\237\272\346\234\254\347\224\250\346\263\225.md" +++ "b/\344\275\277\347\224\250\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242/\345\221\275\344\273\244\350\241\214\347\225\214\351\235\242\345\237\272\346\234\254\347\224\250\346\263\225.md" @@ -11,7 +11,7 @@ $ clitheme Usage: /usr/bin/clitheme apply-theme [themedef-file] [--overlay] [--preserve-temp] /usr/bin/clitheme get-current-theme-info /usr/bin/clitheme unset-current-theme - /usr/bin/clitheme generate-data-hierarchy [themedef-file] [--overlay] + /usr/bin/clitheme generate-data [themedef-file] [--overlay] /usr/bin/clitheme --help /usr/bin/clitheme --version Error: no command or option specified @@ -30,7 +30,7 @@ Error: no command or option specified $ clitheme apply-theme example-theme.clithemedef.txt ==> Generating data... Successfully generated data -==> Applying theme...Success +==> Applying theme... Theme applied successfully ``` 执行这个指令后,支持的应用程序会使用文件中定义的字符串。 @@ -39,11 +39,13 @@ Theme applied successfully 默认情况下,这个指令会覆盖之前的主题数据。你可以通过`--overlay`选项以叠加定义和数据。新的字符串会被添加到当前的数据中,并且已存在的字符串会被覆盖。 + $ clitheme apply-theme --overlay example-theme.clithemedef.txt + **注意:** 使用此选项时需要确保之前已经设定过主题。 -**提示:** 你可以通过此方法叠加多个语言的主题定义文件,因为该功能只会覆盖字符串对应的语言。 +**提示:** 你可以通过此方法叠加多个语言但字符串路径名称相同的的主题定义文件,因为该功能只会覆盖字符串对应的语言。 - $ clitheme apply-theme --overlay example-theme.clithemedef.txt +**提示:** 你可以同时指定多个文件名称,以同时应用这些文件的定义。指定的文件会以从左到右的顺序应用,比如`clitheme apply-theme file1 file2`会先应用`file1`然后再应用`file2`,相当于先应用`file1`然后把`file2`中的定义叠加到当前数据上。 ### 保留临时数据结构目录 @@ -56,7 +58,7 @@ $ clitheme apply-theme --preserve-temp example-theme.clithemedef.txt ==> Generating data... Successfully generated data View at /tmp/clitheme-temp-XXXXXXXX -==> Applying theme...Success +==> Applying theme... Theme applied successfully ``` @@ -66,7 +68,6 @@ Theme applied successfully ``` $ clitheme unset-current-theme -==> Removing data...Success Successfully removed the current theme data ``` @@ -111,14 +112,16 @@ Supported apps: • another-example ``` -## `generate-data-hierarchy` - 生成数据结构 +## `generate-data` - 生成数据结构 -使用`generate-data-hierarchy`指令会在临时目录(`/tmp`)中生成数据结构。该指令的功能和`apply-theme`指令相似,只是不会应用主题而已。 +使用`generate-data`指令会在临时目录中生成数据结构。该指令的功能和`apply-theme`指令相似,只是不会应用主题而已。该指令用于调试和开发用途。 指定`--overlay`选项以生成把主题文件叠加在当前数据上的数据结构,用法和`apply-theme`相同。 +你也可以同时指定多个文件,原理和`apply-theme`一样。 + ``` -$ clitheme generate-data-hierarchy example-theme.clithemedef.txt +$ clitheme generate-data example-theme.clithemedef.txt ==> Generating data... Successfully generated data View at /tmp/clitheme-temp-XXXXXXXX @@ -130,7 +133,7 @@ View at /tmp/clitheme-temp-XXXXXXXX ``` $ clitheme --version -clitheme version 1.0_r1 +clitheme version 1.1-r1 ``` -详细请见**关于版本的重要信息**。 +详细请见[**关于版本的重要信息**](../关于版本的重要信息.md)。 diff --git "a/\345\244\232\350\257\255\350\250\200\346\224\257\346\214\201.md" "b/\345\244\232\350\257\255\350\250\200\346\224\257\346\214\201.md" new file mode 100644 index 0000000000000000000000000000000000000000..07e955cac10d41521e513690af58ce79b6cd9402 --- /dev/null +++ "b/\345\244\232\350\257\255\350\250\200\346\224\257\346\214\201.md" @@ -0,0 +1,86 @@ +# 多语言支持 + +clitheme的核心设计理念之一是对多语言的支持。它可以自动检测当前的系统语言(locale),并且调用对应语言的字符串定义。你可以为一个字符串定义添加不同语言的版本,甚至在主题定义文件内包含你的应用程序中的所有语言的提示信息和字符串。 + +## 语言名称格式 + +语言名称必须是系统语言格式,如`zh_CN`和`en_US`。这个名称由两个小写字母的语言名称和两个大写字母的地区名称组成,并且通过一个下划线分开。有时候,语言名称将会带有格式编码信息,比如`zh_CN.UTF-8`。你不需要包括这个编码信息,意味着使用`zh_CN`和`zh_CN.UTF-8`都可以。 + +你可以在命令行中使用`locale`命令查看当前系统语言(Windows系统除外)。你可以参考输出中的`LANG`和`LANGUAGE`信息作为语言名称。 + +``` +$ locale +LANG="en_US.UTF-8" +LC_COLLATE="en_US.UTF-8" +LC_CTYPE="en_US.UTF-8" +LC_MESSAGES="en_US.UTF-8" +LC_MONETARY="en_US.UTF-8" +LC_NUMERIC="en_US.UTF-8" +LC_TIME="en_US.UTF-8" +LC_ALL= +``` + +## 主题定义文件:为字符串定义添加多个语言版本 + +你可以为一个字符串定于添加多个语言版本。`clitheme`会根据系统语言或者应用程序的语言设定自动选择相应的定义。 + +关于更多信息,请参考[**编写主题定义文件/基本用法**](编写主题定义文件/基本用法.md)中的**使用`entry`段落**。 + +定义字符串时建议添加`default`语言。如果该字符串不支持当前的系统语言,会使用`default`语言定义。如果`default`语言没有被定义,只会在字符串支持当前系统语言的情况下调用该字符串。 + +在多行输入段落下,你可以同时定义多个语言,省去重复复制粘贴内容的过程。 + +**注意:** 目前`clitheme`的自动语言检测不完全支持Windows系统,所以请务必定义`default`语言条目以确保主题定义在Windows系统下生效。 + +``` +# ... +entry com.example example-app example-entry + locale default Your entry text here + locale en_US Your entry text here + locale zh_CN 你的定义文本 + # 或者使用多行输入(可以同时定义多个语言) + locale_block default en_US + Your entry text here + end_block + locale_block zh_CN + 你的定义文本 + end_block +end_entry +``` + +## frontend模块:设定语言和禁用语言检测 + +创建`FetchDescriptor`时,你可以指定以下参数: + +- `lang`:指定了抓取字符串时应该使用的语言;该参数会覆盖`clitheme`自动检测到的系统语言。 + - 你可以指定多个语言;只要用空格分开即可(如`en_US zh_CN`)。获取字符串时会按照顺序依次尝试获取对应语言的字符串定义。 +- `disable_lang`:如果设置为`True`,将会禁用自动语言检测,并且调用功能时将会永远使用当前主题定义中的`default`条目。 + +```py +from clitheme import frontend + +# 使用当前系统语言 +f=frontend.FetchDescriptor() + +# 使用zh_CN语言 +f2=frontend.FetchDescriptor(lang="zh_CN") + +# 如果抓取的字符串定义不支持en_US,则使用zh_CN +f3=frontend.FetchDescriptor(lang="en_US zh_CN") + +# 永远使用字符串定义的default条目 +f4=frontend.FetchDescriptor(disable_lang=True) +``` + +## 技术信息:自动语言检测的原理 + +`clitheme`的自动语言检测的工作方法是读取当前系统中的环境变量信息,并且根据这些信息选择目标语言。 + +以下环境变量信息将通过这个顺序被读取,并且会选择可用性最优先的环境变量作为目标语言: + +- `$LANGUAGE`(多个语言将会被顺序读取,按照该顺序进行字符串定义获取操作) + - `en_US`和`en`将会被忽略(详细请见[本文章](https://wiki.archlinuxcn.org/wiki/Locale#LANGUAGE:后备区域设置)) +- `$LC_ALL` +- `$LANG` + +该顺序参考了GNU gettext的工作原理。详细请见[本文章](https://www.gnu.org/software/gettext/manual/gettext.html#Locale-Environment-Variables)。 \ No newline at end of file diff --git "a/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\345\221\275\344\273\244\350\241\214\346\214\207\344\273\244.md" "b/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\345\221\275\344\273\244\350\241\214\346\214\207\344\273\244.md" new file mode 100644 index 0000000000000000000000000000000000000000..6d0dba19c8b2e37e458fed42a0c7a6bc124f91e3 --- /dev/null +++ "b/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\345\221\275\344\273\244\350\241\214\346\214\207\344\273\244.md" @@ -0,0 +1,436 @@ +# clitheme命令行指令的字符串定义 + +本文章包含了`clitheme`的命令行指令用到的字符串定义,比如`apply-theme`,`get-current-theme-info`等。 + +本文章列出的所有字符串定义将会放在`cli`子路径里,意味着路径名称将会以`swiftycode clitheme cli`开头。 + +## 全局提示 + +### `no-command` + +完整路径名称:`swiftycode clitheme cli no-command` + +默认文本: + +> Error: no command or option specified + +本提示会在没有任何参数的情况下输出。 + +### `not-enough-arguments` + +完整路径名称:`swiftycode clitheme cli not-enough-arguments` + +默认文本: + +> Error: not enough arguments + +本提示会在参数不够的情况下输出(在指定指令的情况下)。 + +### `unknown-option` + +完整路径名称:`swiftycode clitheme cli unknown-option` + +默认文本: + +> Error: unknown option "{option}" + +本提示会在出现未知参数的情况下输出(在指定指令的情况下)。 + +### `unknown-command` + +完整路径名称:`swiftycode clitheme cli unknown-command` + +默认文本: + +> Error: unknown command "{cmd}" + +本提示会在出现未知指令的情况下输出。 + +### `too-many-arguments` + +完整路径名称:`swiftycode clitheme cli too-many-arguments` + +默认文本: + +> Error: too many arguments + +### `help-usage-prompt` + +完整路径名称:`swiftycode clitheme cli help-usage-prompt` + +默认文本: + +> Run {clitheme} --help for usage information + +### `version-str` + +完整路径名称:`swiftycode clitheme cli version-str` + +默认文本: + +> clitheme version {ver} + +本提示会在指定`--version`指令时输出。 + +## `apply-theme`和`generate-data`指令 + +下方列出的字符串定义将会存放在`cli apply-theme`子路径下,意味着路径名称将会以`swiftycode clitheme cli apply-theme`开头。 + +### 样例输出 - `apply-theme` + +``` +$ clitheme apply-theme [...] +The following defintion files will be applied in the following order: +{...} +The existing data will be overwritten if you continue. +Do you want to continue? [y/n] +==> Generating data... + > Processing file 1... + > Processing file 2... + > All finished +Successfully generated data +View at /tmp/clitheme-temp-XXXXXXXX +==> Applying theme... +Theme applied successfully +``` + +对应着以下字符串定义: + +``` +[apply-theme-msg] +{...} +[overwrite-notice] +[confirm-prompt] +[generating-data] +[processing-file] +[processing-file] +[all-finished] +[generate-data-success] +[view-temp-dir] +[applying-theme] +[apply-theme-success] +``` + +### 样例输出 - `generate-data` + +``` +$ clitheme generate-data [...] +The theme data will be generated from the following definition files in the following order: +{...} +==> Generating data... +Successfully generated data +View at /tmp/clitheme-temp-XXXXXXXX +``` + +对应着以下字符串定义: +``` +[generate-data-msg] +{...} +[generating-data] +[generate-data-success] +[view-temp-dir] +``` + +### `generate-data-msg` + +完整路径名称:`swiftycode clitheme cli apply-theme generate-data-msg` + +默认文本: + +> The theme data will be generated from the following definition files in the following order: + +### `apply-theme-msg` + +完整路径名称:`swiftycode clitheme cli apply-theme apply-theme-msg` + +默认文本: + +> The following definition files will be applied in the following order: + +### `overwrite-notice` + +完整路径名称:`swiftycode clitheme cli apply-theme overwrite-notice` + +默认文本: + +> The existing theme data will be overwritten if you continue. + +### `overlay-notice` + +完整路径名称:`swiftycode clitheme cli apply-theme overlay-notice` + +默认文本: + +> The definition files will be appended on top of the existing theme data. + +如果使用`apply-theme`指令时指定了`--overlay`选项,本字符串将会在对应位置输出(详见样例输出),而不是`overwrite-notice`字符串。 + +### `confirm-prompt` + +完整路径名称:`swiftycode clitheme cli apply-theme confirm-prompt` + +默认文本: + +> Do you want to continue? [y/n] + +### `overlay-msg` + +完整路径名称:`swiftycode clitheme cli apply-theme overlay-msg` + +默认文本: + +> Overlay specified + +如果指定了`--overlay`选项,该文本将会在`confirm-prompt`之后被输出。比如: + + {...} + Do you want to continue? [y/n] + Overlay specified + ==> Generating data... + {...} + +### `generating-data` + +完整路径名称:`swiftycode clitheme cli apply-theme generating-data` + +默认文本: + +> ==> Generating data... + +### `processing-file` + +完整路径名称:`swiftycode clitheme cli apply-theme processing-file` + +默认文本: + +> \> Processing file {filename} + +### `all-finished` + +完整路径名称:`swiftycode clitheme cli apply-theme all-finished` + +默认文本: + +> \> All finished + +### `generate-data-success` + +完整路径名称:`swiftycode clitheme cli apply-theme generate-data-success` + +默认文本: + +> Successfully generated data + +### `view-temp-dir` + +完整路径名称:`swiftycode clitheme cli apply-theme view-temp-dir` + +默认文本: + +> View at {path} + +### `applying-theme` + +完整路径名称:`swiftycode clitheme cli apply-theme applying-theme` + +默认文本: + +> ==> Applying theme... + +### `apply-theme-success` + +完整路径名称:`swiftycode clitheme cli apply-theme apply-theme-success` + +默认文本: + +> Theme applied successfully + +### `read-file-error` + +完整路径名称:`swiftycode clitheme cli apply-theme read-file-error` + +默认文本: + +> [File {index}] An error occurred while reading the file: +> +> {message} + +该文本会在文件无法读取时输出。 + +### `overlay-no-data` + +完整路径名称:`swiftycode clitheme cli apply-theme overlay-no-data` + +默认文本: + +> Error: no theme set or the current data is corrupt +> +> Try setting a theme first + +该错误提示仅会在使用`--overlay`选项下输出。 + +### `overlay-data-error` + +完整路径名称:`swiftycode clitheme cli apply-theme overlay-data-error` + +默认文本: + +> Error: the current data is corrupt +> +> Remove the current theme, set the theme, and try again + +### `generate-data-error` + +完整路径名称:`swiftycode clitheme cli apply-theme generate-data-error` + +默认文本: + +> [File {index}] An error occurred while generating the data: +> +> {message} + +### `apply-theme-error` + +完整路径名称:`swiftycode clitheme cli apply-theme apply-theme-error` + +默认文本: + +> An error occurred while applying the theme: +> +> {message} + +## `unset-current-theme` 指令 + +下方列出的字符串定义将会存放在`cli unset-current-theme`子路径下,意味着路径名称将会以`swiftycode clitheme cli unset-current-theme`开头。 + +### `no-data-found` + +完整路径名称:`swiftycode clitheme cli unset-current-theme no-data-found` + +默认文本: + +> Error: No theme data present (no theme was set) + +### `remove-data-error` + +完整路径名称:`swiftycode clitheme cli unset-current-theme remove-data-error` + +默认文本: + +> An error occurred while removing the data: +> +> {message} + +### `remove-data-success` + +完整路径名称:`swiftycode clitheme cli unset-current-theme remove-data-success` + +默认文本: + +> Successfully removed the current theme data + +## `get-current-theme-info` 指令 + +下方列出的字符串定义将会存放在`cli get-current-theme-info`子路径下,意味着路径名称将会以`swiftycode clitheme cli get-current-theme-info`开头。 + +### 样例输出 + +``` +Currently installed theme: +[1]: Example theme +Version: 1.0 +Description: +{...} +Supported locales: +• en_US +• zh_CN +Supported apps: +• App 1 +• App 2 +``` + +对应着以下字符串定义: + +``` +[current-theme-msg] +none +[version-str] +[description-str] +{...} +[locales-str] +[list-item] +[list-item] +[supported-apps-str] +[list-item] +[list-item] +``` + +### `no-theme` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info no-theme` + +默认文本: + +> No theme currently set + +该提示会在没有设定任何主题的情况下输出。 + +### `current-theme-msg` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info current-theme-msg` + +默认文本: + +> Currently installed theme: + +### `overlay-history-msg` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info overlay-history-msg` + +默认文本: + +> Overlay history (sorted by latest installed): + +如果之前通过`apply-theme --overlay`指令同时应用过多个主题,该文本将会替换`current-theme-msg`的文本,在相同位置显示(详见样例输出)。 + +### `version-str` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info version-str` + +默认文本: + +> Version: {ver} + +### `description-str` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info description-str` + +默认文本: + +> Description: + +### `locales-str` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info locales-str` + +默认文本: + +> Supported locales: + +### `supported-apps-str` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info supported-apps-str` + +默认文本: + +> Supported apps: + +### `list-item` + +完整路径名称:`swiftycode clitheme cli get-current-theme-info list-item` + +默认文本: + +> • {content} + +你可以通过此定义控制项目列表的样式,会在`Supported apps: `和`Supported locales:`下展示。(详见输出样例) diff --git "a/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\346\225\260\346\215\256\347\224\237\346\210\220\345\231\250\346\217\220\347\244\272\344\277\241\346\201\257.md" "b/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\346\225\260\346\215\256\347\224\237\346\210\220\345\231\250\346\217\220\347\244\272\344\277\241\346\201\257.md" new file mode 100644 index 0000000000000000000000000000000000000000..08f5faa8a39f35bf584b711defa541d474763565 --- /dev/null +++ "b/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\346\225\260\346\215\256\347\224\237\346\210\220\345\231\250\346\217\220\347\244\272\344\277\241\346\201\257.md" @@ -0,0 +1,181 @@ +# clitheme数据生成器提示信息的字符串定义 + +本文章包含了`clitheme`数据生成器用到的字符串定义。该数据生成器用于`apply-theme`指令中的数据生成部分。 + +本文章列出的字符串都会放在`generator`子路径里,意味着所有的路径名称将会以`swiftycode clitheme generator`开头。 + +样例提示信息输出(`apply-theme`指令): + +``` +{...} +==> Generating data... +[File 1] An error occurred while generating the data: +Syntax error: Unexpected "phrase" on line 4 +``` + +## 语法错误提示 + +### `error-str` + +完整路径名称:`swiftycode clitheme generator error-str` + +默认文本: + +> Syntax error: {msg} + +所有的语法错误信息将会通过这个文本输出(文本中的`{msg}`部分)。详见上方的样例输出。 + +### `subsection-conflict-err` + +完整路径名称:`swiftycode clitheme generator subsection-conflict-err` + +默认文本: + +> Line {num}: cannot create subsection "{name}" because an entry with the same name already exists + + +### `entry-conflict-err` + +完整路径名称:`swiftycode clitheme generator entry-conflict-err` + +默认文本: + +> Line {num}: cannot create entry "{name}" because a subsection with the same name already exists + +### `internal-error-blockinput` + +完整路径名称:`swiftycode clitheme generator internal-error-blockinput` + +默认文本: + +> Line {num}: internal error while handling block input; please file a bug report + +### `extra-arguments-err` + +完整路径名称:`swiftycode clitheme generator extra-arguments-err` + +默认文本: + +> Extra arguments after "{phrase}" on line {num} + +### `repeated-header-err` + +完整路径名称:`swiftycode clitheme generator repeated-header-err` + +默认文本: + +> Repeated header block at line {num} + +### `repeated-main-err` + +完整路径名称:`swiftycode clitheme generator repeated-main-err` + +默认文本: + +> Repeated main block at line {num} + +### `invalid-phrase-err` + +完整路径名称:`swiftycode clitheme generator invalid-phrase-err` + +默认文本: + +> Unexpected "{phrase}" on line {num} + +### `not-enough-args-err` + +完整路径名称:`swiftycode clitheme generator not-enough-args-err` + +默认文本: + +> Not enough arguments for "{phrase}" at line {num} + +### `subsection-before-domainapp-err` + +完整路径名称:`swiftycode clitheme generator subsection-before-domainapp-err` + +默认文本: + +> Line {num}: in_subsection used before in_domainapp + +### `incomplete-block-err` + +完整路径名称:`swiftycode clitheme generator subsection-before-domainapp-err` + +默认文本: + +> Missing or incomplete header or main block + +## 语法警告提示 + +### `warning-str` + +完整路径名称:`swiftycode clitheme generator warning-str` + +默认文本: + +> Warning: {msg} + +和`error-str`类似,所有的语法警告信息将会通过这个文本输出(文本中的`{msg}`部分)。 + +### `repeated-entry-warn` + +完整路径名称:`swiftycode clitheme generator repeated-entry-warn` + +默认文本: + +> Line {num}: repeated entry "{name}", overwriting + +### `repeated-header-warn` + +完整路径名称:`swiftycode clitheme generator repeated-header-warn` + +默认文本: + +> Line {num}: repeated header info "{name}", overwriting + +## 名称不合规提示 + +数据生成器会对文件内的路径名称进行检查,以确保文件中没有不合规的名称。详见[应用程序适配/路径名称和数据结构.md](../应用程序适配/路径名称和数据结构.md)中的**注意事项**。 + +所有相关的提示信息都会通过`sanity-check-entry-err`,`sanity-check-domainapp-err`,或`sanity-check-subsection-err`中的`{sanitycheck_msg}`显示。 + +### `sanity-check-entry-err` + +完整路径名称:`swiftycode clitheme generator sanity-check-entry-err` + +默认文本: + +> Line {num}: entry subsections/names {sanitycheck_msg} + +### `sanity-check-domainapp-err` + +完整路径名称:`swiftycode clitheme generator sanity-check-domainapp-err` + +默认文本: + +> Line {num}: entry subsections/names {sanitycheck_msg} + +### `sanity-check-subsection-err` + +完整路径名称:`swiftycode clitheme generator sanity-check-subsection-err` + +默认文本: + +> Line {num}: subsection names {sanitycheck_msg} + +### `sanity-check-msg-banphrase-err` + +完整路径名称:`swiftycode clitheme generator sanity-check-msg-banphrase-err` + +默认文本: + +> cannot contain '{char}' + +### `sanity-check-msg-startswith-err` + +完整路径名称:`swiftycode clitheme generator sanity-check-msg-startswith-err` + +默认文本: + +> cannot start with '{char}' \ No newline at end of file diff --git "a/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\350\207\252\345\256\232\344\271\211clitheme\347\232\204\350\276\223\345\207\272.md" "b/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\350\207\252\345\256\232\344\271\211clitheme\347\232\204\350\276\223\345\207\272.md" new file mode 100644 index 0000000000000000000000000000000000000000..0fcb2c9692bc692a013d6e1ccb2ca4dab29a2149 --- /dev/null +++ "b/\345\255\227\347\254\246\344\270\262\345\256\232\344\271\211/\350\207\252\345\256\232\344\271\211clitheme\347\232\204\350\276\223\345\207\272.md" @@ -0,0 +1,16 @@ +# 自定义clitheme命令行界面的输出 + +你可以通过编写主题定义文件对clitheme的命令行界面输出进行修改和自定义。本文件夹内的文章提供了所有所需的信息,包含所有支持的字符串定义和对应的路径名称和其他信息。 + +请保留字符串中带有花括号的词汇,比如`{content}`,否则自定义文本将不会生效。 + +有关编写主题定义文件的信息,请参考[编写主题定义文件/基本用法.md](../编写主题定义文件/基本用法.md)。 + +## 开发者和应用名称 + +clitheme所有字符串定义的路径名称将采用以下开发者和应用名称,并且永远会以这些名称开头。详见[应用程序适配/路径名称和数据结构.md](../应用程序适配/路径名称和数据结构.md)。 + +- 开发者名称:`swiftycode` +- 应用程序名称:`clitheme` + +所有的路径名称将会以`swiftycode clitheme`开头。比如说:`swiftycode clitheme example-definition` diff --git "a/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\345\211\215\347\253\257API\345\256\214\346\225\264\346\226\207\346\241\243.md" "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/frontend\346\250\241\345\235\227\345\256\214\346\225\264\346\226\207\346\241\243.md" similarity index 34% rename from "\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\345\211\215\347\253\257API\345\256\214\346\225\264\346\226\207\346\241\243.md" rename to "\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/frontend\346\250\241\345\235\227\345\256\214\346\225\264\346\226\207\346\241\243.md" index 54102115eecbfa85f4b843c91a2f1dc718b88986..81dbccdb7d848bbf643d0f494d8d54f2354a5cff 100644 --- "a/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\345\211\215\347\253\257API\345\256\214\346\225\264\346\226\207\346\241\243.md" +++ "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/frontend\346\250\241\345\235\227\345\256\214\346\225\264\346\226\207\346\241\243.md" @@ -1,36 +1,72 @@ -# 前端API(frontend)文档 +# frontend模块完整文档 -本文章包括了`frontend`模块的完整文档。如需样例和更多信息,请参考上一个文章**使用前端API**。 +本文章包括了`frontend`模块的完整文档。如需样例和更多信息,请参考[**使用frontend模块**](使用frontend模块.md)。 ## `FetchDescriptor` 类 ### `__init__` -`__init__`(`domain_name`: `str`,`app_name`: `str`, `subsections`: `str`, `lang`: `str`, `debug_mode`: `bool`, `disable_lang`: `bool`) +`frontend.FetchDescriptor`(`domain_name`: `str`,`app_name`: `str`, `subsections`: `str`, `lang`: `str`, `debug_mode`: `bool`, `disable_lang`: `bool`) -创建新的`FetchDescriptor`实例。 +创建新的`FetchDescriptor`实例。所有的参数是可选的,不需要全部指定。 -- 指定`domain_name`,`app_name`,`subsections`以把这些数值自动添加到功能引用的参数中。 +- 指定`domain_name`,`app_name`,和`subsections`以把这些数值自动添加到功能引用的参数中。 - 指定`lang`以自定义使用的字符串语言。 - 设定`debug_mode`为`True`以调用功能时输出更多用于调试的信息。 - 设定`disable_lang`为`True`以禁用自定义和自动语言检测,并且永远使用字符串中的`default`语言定义。 ### `retrieve_entry_or_fallback` -`retrieve_entry_or_fallback`(`entry_path`: `str`, `fallback_string`: `str`) -> `str` +`frontend.FetchDescriptor.retrieve_entry_or_fallback`(`entry_path`: `str`, `fallback_string`: `str`) -> `str` + +`frontend.FetchDescriptor.reof`(`entry_path`: `str`, `fallback_string`: `str`) -> `str` 尝试根据提供的`entry_path`获取并返回对应的字符串。如果创建`FetchDescriptor`时指定了`domain_name`,`app_name`,和`subsections`,这些信息会自动被添加到`entry_path`的前面。 -如果找不到对应的字符串和路径名称,返回提供的`fallback_string`。 +如果找不到对应的字符串和路径名称,该函数会返回提供的`fallback_string`。 + +### `format_entry_or_fallback` + +`frontend.FetchDescriptor.format_entry_or_fallback`(`entry_path`: `str`, `fallback_string`: `str`, `*args`, `**kwargs`) -> `str` + +`frontend.FetchDescriptor.feof`(`entry_path`: `str`, `fallback_string`: `str`, `*args`, `**kwargs`) -> `str` + +尝试根据提供的`entry_path`获取并返回通过提供的format参数(args和kwargs)格式化后的字符串。如果创建`FetchDescriptor`时指定了`domain_name`,`app_name`,和`subsections`,这些信息会自动被添加到`entry_path`的前面。 + +如果找不到对应的字符串和路径名称,或者格式化获取的字符串时出现了错误,该函数会返回用format参数格式化后的`fallback_string`。 + +**注意:** 请务必确保`fallback_string`能被成功使用`str.format`函数格式化,并且所有的format参数都被`fallback_string`引用,否则调用此函数时会发生错误。 ### `entry_exists` -`entry_exists`(`entry_path`: `str`) -> `bool` +`frontend.FetchDescriptor.entry_exists`(`entry_path`: `str`) -> `bool` 检查对应的路径名称和字符串是否存在。如果存在,返回`True`。否则,返回`False`。 如果创建`FetchDescriptor`时指定了`domain_name`,`app_name`,和`subsections`,这些信息会自动被添加到`entry_path`的前面。 +## 设定本地定义文件 + +关于更多信息,请见[**调用本地主题定义文件**](调用本地主题定义文件.md)。 + +### `set_local_themedef` + +`frontend.set_local_themedef`(`file_content`: `str`, `overlay`: `bool`=`False`) -> `bool` + +设定本地定义文件。设定后,当系统全局主题设定没有请求的字符串时frontend会尝试调用本地定义文件里的定义。 + +当设定成功时,该函数会返回`True`,否则该函数会返回`False`。 + +- 设定`overlay`为`True`以把当前定义文件叠加到当前数据上。 + +**注意:** 请将**文件内容**传递到这个函数中,不要传递文件的路径名称。 + +### `unset_local_themedef` + +`frontend.unset_local_themedef`() + +取消设定本地定义文件。取消设定后frontend将不再尝试调用本地定义文件。 + ## 全局变量和选项 以下的变量定义会对所有之后创建的`FetchDescriptor`生效,除非定义`FetchDescriptor`时指定了其他的数值。 diff --git "a/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\344\275\277\347\224\250\345\211\215\347\253\257API.md" "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\344\275\277\347\224\250frontend\346\250\241\345\235\227.md" similarity index 49% rename from "\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\344\275\277\347\224\250\345\211\215\347\253\257API.md" rename to "\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\344\275\277\347\224\250frontend\346\250\241\345\235\227.md" index 54595ef7dc5d3c78d95f43d9ec034a218d760ee9..a3d98eb1c2e3f6d67935bd260afa024276a34285 100644 --- "a/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\344\275\277\347\224\250\345\211\215\347\253\257API.md" +++ "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\344\275\277\347\224\250frontend\346\250\241\345\235\227.md" @@ -1,14 +1,14 @@ # 使用clitheme的frontend模块 -为了帮助开发者更方便的添加`clitheme`的适配,本项目提供了一个前端API(frontend)模块。这个模块包含了抓取当前主题中字符串的功能;只需要调用一个函数就可以了。除此之外,frontend还包括了其他的功能,比如检查当前的主题有没有适配请求的字符串。我打算将在后续版本中添加更多的功能,敬请期待。 +为了帮助开发者更方便的添加`clitheme`的适配,本项目提供了一个frontend模块。这个模块包含了抓取当前主题中字符串的功能;只需要调用一个函数就可以了。除此之外,frontend还包括了其他的功能,比如检查当前的主题有没有适配请求的字符串。我打算将在后续版本中添加更多的功能,敬请期待。 -**注意:** 目前frontend模块只支持使用Python 3编写的应用程序;其他语言编写的程序需要自行访问数据结构。如需更多信息,请见**路径名称和数据结构**。 +**注意:** 目前frontend模块只支持使用Python 3编写的应用程序;其他语言编写的程序需要自行访问数据结构。如需更多信息,请见[**路径名称和数据结构**](路径名称和数据结构.md)。 ## 新建`FetchDescriptor`类 -前端API使用了一个叫`FetchDescriptor`的一个类,并且所有的功能都包含在这个类里面。初始化`FetchDesciptor`时可以提供如开发者,应用名称,和子路径等信息,调用功能时会自动把这些信息添加到提供的路径名称中,帮你减少代码量。 +frontend模块使用了一个叫`FetchDescriptor`的一个类,并且所有的功能都包含在这个类里面。初始化`FetchDesciptor`时可以提供如开发者,应用名称,和子路径等信息,调用功能时会自动把这些信息添加到提供的路径名称中,帮你减少代码量。 -如需创建`FetchDescriptor`,请导入frontend模块,并使用以下代码: +如需创建`FetchDescriptor`,请导入frontend模块,并参考以下代码: ```py from clitheme import frontend @@ -17,6 +17,7 @@ f = frontend.FetchDescriptor( \ domain_name="com.example", \ app_name="example-app", \ subsections="example-subsection subsection-2" \ + lang="en_US" \ debug_mode=False, \ disable_lang=False) ``` @@ -24,13 +25,14 @@ f = frontend.FetchDescriptor( \ `FetchDescriptor`支持以下参数: - `domain_name`,`app_name`,`subsections`:指定开发者名称,应用名称,和子路径;调用功能时会自动添加到路径中 -- `lang`:指定并且覆盖`clitheme`检测到的系统语言信息,并且使用自定义语言(如`zh_CN`,`en_US`,`en_US.UTF-8`等) +- `lang`:指定并且覆盖`clitheme`检测到的系统语言信息(详见[**多语言支持**](../多语言支持.md)),并且使用该参数定义的语言信息(如`zh_CN`,`en_US`,`en_US.UTF-8`等) + - 你可以指定多个语言;只要用空格分开即可(如`en_US zh_CN`)。获取字符串时会按照顺序依次尝试获取对应语言的字符串定义。 - `debug_mode`:如果设置为`True`,调用功能时会输出更多信息,用于调试作用 - `disable_lang`:如果设置为`True`,将会禁用自动语言检测,并且调用功能时将会永远使用当前主题定义中的`default`条目。 ### 创建后修改参数/设置 -你可以在创建`FetchDescriptor`后修改这些参数。只需要修改对应的变量就可以了。比如说: +你可以在创建`FetchDescriptor`后修改这些参数;只需要修改对应的变量就可以了。比如说: ```py f.debug_mode=True @@ -39,14 +41,17 @@ f.disable_lang=True ## 使用`retrieve_entry_or_fallback`函数 -如需获取当前主题定义的某个字符串,请使用`FetchDescriptor`中的`retrieve_entry_or_fallback`函数。调用时需要提供路径名称和默认字符串。如果当前主题设定没有适配该字符串,则函数会返回提供的默认字符串。你可以将这个函数调用包括在一个`print`语句中,以输出返回的结果。 +如需获取当前主题定义的某个字符串,请使用`FetchDescriptor`中的`retrieve_entry_or_fallback`函数。调用时需要提供路径名称和默认字符串。如果当前主题设定没有适配该字符串,则该函数会返回提供的默认字符串。你可以将这个函数调用包括在一个`print`语句中,以输出返回的结果。 -该函数会读取系统上的语言设置(`$LANG`环境变量),并且会优先返回主题定义中对应语言的字符串。该行为可以在创建`FetchDescriptor`时禁用(详见上面)。 +该函数会读取系统上的语言设置(详见[**多语言支持**](../多语言支持.md)),并且会优先返回主题定义中对应语言的字符串。该行为可以在创建`FetchDescriptor`时禁用(详见上面)。 你也可以使用更简短的`reof`函数定义以减少代码量。 +**注意:** 该函数返回的字符串(除返回`fallback_string`之外)不会包含任何末尾空格。 + ```py -# [...] +# [对接上方的f=FetchDescriptor(...)定义] + # 对应com.example example-app example-subsection subsection-2 example-entry f.retrieve_entry_or_fallback("example-entry", "Default text goes here") @@ -58,10 +63,32 @@ f2=frontend.FetchDescriptor() f2.reof("com.example example-app example-subsection subsection-2 example-entry", "Default text goes here") ``` +## 使用`format_entry_or_fallback`函数 + +如果获取字符串后需要使用`str.format`函数格式化字符串,你可以使用`FetchDescriptor`中的`format_entry_or_fallback`函数。该函数可以自动帮你处理因字符串格式不正确导致的报错,防止格式不正确的字符串定义导致你的应用程序无法正常运行的问题。如果当前主题设定没有适配该字符串或者格式化获取的字符串时出现错误,则该函数会返回提供的默认字符串。 + +你也可以使用更简短的`feof`函数定义以减少代码量。 + +如需使用此函数,请将路径名称,默认字符串,和用于`str.format`的参数提供到函数中。 + +```py +# 默认字符串返回值:"program: Current value is 1" +f.format_entry_or_fallback("example-fmt-entry", "{0}: Current value is {value}", "program", value="1") + +# 该函数调用等于以下代码: +f.retrieve_entry_or_fallback("example-fmt-entry", "{0}: Current value is {value}").format("program", value="1") +``` + ## 全局定义参数 除了在`FetchDescriptor`中定义这些选项和参数,你可以对程序中所有的`FetchDescriptor`设置这些参数。以下变量定义会对所有的`FetchDescriptor`生效,除非创建`FetchDescriptor`时明确指定了这些参数。 +- `global_domain`,`global_appname`,和`global_subsections`:指定了默认的`domain_name`,`app_name`,和`subsections`数值 +- `global_debugmode`:指定了默认的`debug_mode`数值 + - 该数值也会控制`frontend.set_local_themedef`函数的输出(详见[**调用本地主题定义文件**](调用本地主题定义文件.md)) +- `global_lang`:指定了默认的`lang`数值 +- `global_disablelang`:指定了默认的`disable_lang`数值 + **请注意:** 这些全局定义只会影响之后新建的`FetchDescriptor`;更改或设定这些全局定义不会影响已经创建的`FetchDescriptor`。 ```py @@ -69,7 +96,7 @@ from clitheme import frontend f0=frontend.FetchDescriptor() # 不会使用定义的全局变量 -# 默认值 +# 默认值: # frontend.global_domain="" # frontend.global_appname="" # frontend.global_subsections="" @@ -93,9 +120,9 @@ f2=frontend.FetchDescriptor() f3=frontend.FetchDescriptor(debug_mode=True) ``` -## 使用前端fallback模块 +## 使用fallback模块 -你可以在你的项目中内置本项目提供的fallback模块,以便更好的处理`clitheme`模块不存在时的情况。该fallback模块包括了前端API中的所有定义和功能,并且会永远返回失败时的默认值(fallback)。 +你可以在你的项目中内置本项目提供的fallback模块,以便更好的处理`clitheme`模块不存在时的情况。该fallback模块包括了frontend模块中的所有定义和功能,并且会永远返回失败时的默认值(fallback)。 如需使用,请在你的项目文件中导入仓库中的`clitheme_fallback.py`文件,并且在你的程序中包括以下代码: @@ -105,7 +132,8 @@ try: except (ModuleNotFoundError, ImportError): import clitheme_fallback as frontend ``` +本项目提供的fallback文件会随版本更新而更改,所以请定期往你的项目里导入最新的fallback文件以获得最新的功能。 ## 样例 -如需关于前端API调用的样例,请参考本仓库中的`clitheme_example.py`文件。 \ No newline at end of file +如需关于使用frontend模块的样例,请参考本仓库中的`clitheme_demo.py`文件。 \ No newline at end of file diff --git "a/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\350\260\203\347\224\250\346\234\254\345\234\260\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266.md" "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\350\260\203\347\224\250\346\234\254\345\234\260\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266.md" new file mode 100644 index 0000000000000000000000000000000000000000..99a6c4fbc875e52ae716aa32d9f94c76307eb448 --- /dev/null +++ "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\350\260\203\347\224\250\346\234\254\345\234\260\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266.md" @@ -0,0 +1,46 @@ +# 使用本地定义文件 + +你的应用程序除了可以通过frontend适配这个框架,你的应用程序还可以调用一个本地的定义文件。设定了本地定义文件后,frontend访问字符串时会先尝试访问系统/全局主题设定然后再尝试访问这个本地定义文件中的字符串定义。一般情况下,你应该把本地定义文件放在应用程序中的资源文件内,或者把它的内容放在程序中的一个变量内。 + +本地定义文件可以用于: +- 为你的应用程序适配多个语言 +- 包括应用程序中所有所需的的字符串和提示信息,修改起来更简单 + +## 设定本地定义 + +设定本地定义文件可以使用`frontend.set_local_themedef`函数,并且把文件的内容传给这个函数。(**注意:** 不是文件的路径名称,而是文件读取后的内容) + +当设定成功时,该函数会返回`True`,否则该函数会返回`False`。 + +如需设定本地定义文件,你可以在相应的代码文件中添加以下调用: + +```py +from clitheme import frontend +f=open("", "r") # 为文件路径 +c=f.read() +frontend.set_local_themedef(c) +``` + +设定完成后会对之后的字符串调用操作生效。获取字符串时,只有当前系统/全局主题设定中没有该字符串定义的情况下才会调用本地文件中的定义。 + +## 同时设定多个本地定义文件 + +你可以通过`set_local_themedef`函数中的`overlay`参数同时设定多个本地定义文件。如需使用,请在每次的函数调用指定这个参数。 + +```py +from clitheme import frontend +# ... +# 第一个调用不需要指定overlay +frontend.set_local_themedef(file_content1) +frontend.set_local_themedef(file_content2, overlay=True) +frontend.set_local_themedef(file_content3, overlay=True) +``` + +## 取消设定 + +如需取消设定本地定义文件,请使用`frontend.unset_local_themedef`函数。取消设定后,frontend将不会尝试调用本地定义文件中的字符串定义。 + +```py +# ... +frontend.unset_local_themedef() +``` diff --git "a/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\350\267\257\345\276\204\345\220\215\347\247\260\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204.md" "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\350\267\257\345\276\204\345\220\215\347\247\260\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204.md" index 3cf4eab6af6caebe8fc4a1ce5fed74661ec89821..75afd8a56016ac961addbf4e9dc285ae707f8fb8 100644 --- "a/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\350\267\257\345\276\204\345\220\215\347\247\260\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204.md" +++ "b/\345\272\224\347\224\250\347\250\213\345\272\217\351\200\202\351\205\215/\350\267\257\345\276\204\345\220\215\347\247\260\345\222\214\346\225\260\346\215\256\347\273\223\346\236\204.md" @@ -2,24 +2,24 @@ 应用程序是主要通过**路径名称**来指定所需的字符串。这个路径由空格来区别子路径(`subsections`)。大部分时候路径的前两个名称是用来指定开发者和应用名称的。主题文件会通过该路径名称来适配对应的字符串,从而达到自定义输出的效果。 -如果当前主题没有适配请求的字符串,前端API会返回函数调用时提供的备用字符串。 - 比如`com.example example-app example-text`指的是`com.example`开发的`example-app`中的`example-text`字符串。 当然,路径名称也可以是全局的(不和任何应用信息关联),如`global-entry`或`global-example global-text`。 ## 直接访问主题数据结构 -`clitheme`的核心设计理念之一包括无需使用前端API就可以访问主题数据,并且访问方法直观易懂。这一点在使用其他语言编写的程序中尤其重要,因为前端API目前只提供Python程序的支持。 +`clitheme`的核心设计理念之一包括无需使用frontend模块就可以访问主题数据,并且访问方法直观易懂。这一点在使用其他语言编写的程序中尤其重要,因为frontend模块目前只提供Python程序的支持。 `clitheme`的数据结构采用了**子文件夹**的结构,意味着路径中的每一段代表着数据结构中的一个文件夹/文件。 -比如说,`com.example example-app example-text` 的字符串会被存储在`$datapath/com.example/example-app/example-text`。一般情况下,`$datapath`(数据根目录)是 `$XDG_DATA_HOME/clitheme/theme-data`或`~/.local/share/clitheme/theme-data`。 +比如说,`com.example example-app example-text` 的字符串会被存储在`/com.example/example-app/example-text`。在Linux和macOS系统下,``是 `$XDG_DATA_HOME/clitheme/theme-data`或`~/.local/share/clitheme/theme-data`。 + +在Windows系统下,``是`%USERPROFILE%\.local\share\clitheme\theme-data`。(`C:\Users\<用户名称>\.local\share\clitheme\theme-data`) -如果需要访问该字符串的其他语言,直接在路径的最后添加`__`加上locale名称就可以了。比如:`$datapath/com.example/example-app/example-text__zh_CN` +如果需要访问该字符串的其他语言,直接在路径的最后添加`__`加上locale名称就可以了。比如:`/com.example/example-app/example-text__zh_CN` 所以说,如果需要直接访问字符串信息,只需要访问对应的文件路径就可以了。 ## 注意事项 -- 路径名称的任何子路径不能包括像`/`,`\`等符号,并且不能以`.`开头。 +- 路径名称的任何子路径不能包括`/`和`\`符号,并且不能以`.`开头。 diff --git "a/\347\256\200\344\273\213.md" "b/\347\256\200\344\273\213.md" index 96c11e8328047c4e510acde5b6c4cd20e88a8a29..b851bb642e395155c207cd9810490ea96887a5d0 100644 --- "a/\347\256\200\344\273\213.md" +++ "b/\347\256\200\344\273\213.md" @@ -2,7 +2,7 @@ `clitheme`是一个主要面向命令行应用程序的文本主题/自定义框架。它允许你修改和自定义命令行应用程序的提示和输出;只要应用程序适配了这个框架就可以。通过编写**主题定义文件**,你可以给你最喜爱的应用程序添加你想要的风格和个性。无论是把它们变得活泼可爱,模拟二次元角色的语句,甚至只是添加多语言支持,`clitheme`允许你自由发挥你的想象,把你的命令行环境变成你想要的样子。 -**这些文档适配`clitheme`的`v1.0-r2`版本。** +**这些文档适配`clitheme`的`v1.1`版本。** ## 样例 @@ -70,4 +70,4 @@ $ example-app install-file foo-nonexist ಥ_ಥ 糟糕,出错啦!找不到文件 "foo-nonexist" ``` -我们可以看到这个工具输出了你自定义的字符串,变成了你想要的样子。关于编写主题定义文件的更多信息,请参考Wiki文章**主题文件的编写**。 \ No newline at end of file +我们可以看到这个工具输出了你自定义的字符串,变成了你想要的样子。关于编写主题定义文件的更多信息,请参考Wiki文章[**编写主题定义文件/基本用法**](编写主题定义文件/基本用法.md)。 \ No newline at end of file diff --git "a/\347\274\226\345\206\231\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266/\345\237\272\346\234\254\347\224\250\346\263\225.md" "b/\347\274\226\345\206\231\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266/\345\237\272\346\234\254\347\224\250\346\263\225.md" index 4c883cc4e82db780288d5a312ae472ce22acd37c..34be4724b318303bdd95932280b8a66f26d48323 100644 --- "a/\347\274\226\345\206\231\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266/\345\237\272\346\234\254\347\224\250\346\263\225.md" +++ "b/\347\274\226\345\206\231\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266/\345\237\272\346\234\254\347\224\250\346\263\225.md" @@ -32,6 +32,7 @@ 在`header`段落内可以定义以下信息。你不需要定义所有的信息,但是建议定义以下所有的信息。 - `name`:定义该主题的名称,如**example-app颜文字主题**。 +- `description`: 定义该主题的更多详细信息。 - `version`:定义该主题的版本。比如说,如果你添加或修改了其中的内容,你可以通过这个信息来跟踪修改版本,如`1.0`。 - `locales`:定义主题支持哪些语言。如果支持多个语言,请使用空格分开。比如:`en_US zh_CN`或`English Chinese` - `supported_apps`:定义主题支持的应用程序。如果支持多个应用程序,请使用空格分开。比如:`example-app example-app-2 another-example-app` @@ -43,9 +44,10 @@ ``` begin_header name example-app颜文字主题 + description 为example-app制作的一个可爱的颜文字主题 version 1.0 locales zh_CN en_US - supported_apps clitheme_example example-app example-app-2 + supported_apps example-app example-app-2 end_header ``` @@ -65,7 +67,7 @@ end_header `clitheme`的核心设计理念之一是多语言支持,所以字符串本体需要在`locale`行中定义。`locale`行的格式为:`locale <字符串>`。当前的系统语言会被自动获取,并且会使用对应的定义。 -`locale`中的语言必须是系统语言格式,如`zh_CN`和`en_US`。你可以在命令行中使用`locale`命令查看当前系统语言。 +`locale`中的语言必须是系统语言格式,如`zh_CN`和`en_US`。你可以在命令行中使用`locale`命令查看当前系统语言。(详见文章**多语言支持**) 定义字符串时建议添加`default`语言(`locale default <字符串>`)。如果该字符串不支持当前的系统语言,会使用`default`语言定义。如果`default`语言没有被定义,只会在字符串支持当前系统语言的情况下调用该字符串。 @@ -86,7 +88,7 @@ end_entry 你可以使用`in_domainapp`和`in_subsection`以节省文件中的代码量。被定义时,这个信息会自动被添加在所有的`entry`定义前,以` `的格式处理。 -如需了解关于子路径的更多信息,请参考**应用程序适配**->**路径名称和数据结构**。 +如需了解关于子路径的更多信息,请参考[**应用程序适配/路径名称和数据结构**](../应用程序适配/路径名称和数据结构.md)。 `in_domainapp`的格式为`in_domainapp `,并且不能有多余的空格。`in_subsection`的格式为`in_subsection `,并且可以有多个subsection和空格。 diff --git "a/\347\274\226\345\206\231\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266/\345\244\232\350\241\214\350\276\223\345\205\245.md" "b/\347\274\226\345\206\231\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266/\345\244\232\350\241\214\350\276\223\345\205\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..f971baa9cce8bfd691bf73903bcec760bdda5ae0 --- /dev/null +++ "b/\347\274\226\345\206\231\344\270\273\351\242\230\345\256\232\344\271\211\346\226\207\344\273\266/\345\244\232\350\241\214\350\276\223\345\205\245.md" @@ -0,0 +1,117 @@ +# 多行输入功能 + +主题定义文件中的部分定义支持段落输入/多行输入。它允许你在一个定义中包括拥有多个行数的字符串,或允许你定义带有空格的名称和项目。 + +如需定义多行输入段落,请在支持的定义名称后添加`_block`字样(比如:`locales_block`, `description_block`),并且使用`end_block`结束段落。 + +## header段落 + +在`header`段落中,以下定义支持多行输入: +- `description`(`description_block`) +- `supported_apps`(`supported_apps_block`) +- `locales`(`locales_block`) + +在`supported_apps_block`和`locales_block`中,多个项目标注将以换行分开,而不是空格分开。这允许你在项目名称内插入空格。比如: + +``` +begin_header + # <...> + description_block + Some description here + Another description here + end_block + locales_block + Simplified Chinese (zh_CN) + English (en_US) + end_block + supported_apps_block + App one + App two + App three + end_block +end_header +``` + +使用`clitheme get-current-theme-info`列出信息时会这样展示: + +``` +<...> +Description: +Some description here +Another description here + +Supported locales: +• Simplified Chinese (zh_CN) +• English (en_US) +Supported apps: +• App one +• App two +• App three +``` + +## main段落 + +在`main`段落中,`entry`中的字符串定义(`locale`)支持多行输入,并且通过`locale_block`定义。 + +**提示:** 你可以定义多个语言,省去重复复制粘贴的过程。多个语言由空格分开。 + +``` +begin_header + <...> + entry example-entry + # 你可以定义多个语言 + locale_block en_US C zh_CN + This is an entry + Another line like that + A new line + end_block + end_entry +``` + +应用程序调用`example-entry`时会显示: + +``` +This is an entry +Another line like that +A new line +``` + + +## 关于缩进/边缘空格的处理 + +**注意:** 多行输入内容中的结尾空格及whitespace将会被忽略。 + +但是,起始空格和whitespace会被减去多行输入内容内的共同whitespace大小(tab符号将会被视为8个空格)。这意味着行数之间的缩进差距将会被保留,但是暂不支持在仅有一行的内容中保留缩进和空格。 + +这意味着: + +``` +entry entry1 + locale_block default + Text 1 + Text 2 + Text 3 + Text 4 + end_block +end_entry +entry entry2 + locale_block default + Text 1 + end_block +end_entry + +``` + +被读取时会返回以下内容: + +`entry1`: +``` +Text 1 + Text 2 + Text 3 +Text 4 +``` + +`entry2`: + + Text 1 \ No newline at end of file