Skip to main content

Translation System

The translation system is the internationalization mechanism of the Alia language, supporting the translation of keywords and objects into different natural languages or keyword systems.

1. Defining Translations​

Syntax​

@translateAlias <String targetLanguage> <Keys GeneralKeywords> -> <Keys SpecificLanguageKeywords>
@translateClass <String targetLanguage> <Key ObjectName> <Array ObjectKeys> -> <Key newObjectName> <Array newObjectKeys>
@language <String targetLanguage>
@clearLanguage

@translateClass only registers the mapping of the first member name inside the square brackets (e.g. [加入] mapping to [push]); the class name itself is not translated.

Functionality​

KeywordFunction
@translateAliasTranslates general keywords into the keywords of a specific language
@translateClassRegisters a mapping from object member names in a specific language to general member names, effective only after . member access
@languageSets the keyword system in use (additive; multiple language paradigms can be enabled simultaneously)
@clearLanguageRestores keywords to the default "Default"

Scope​

  • When @language is declared at the top of a file, it applies to the entire file
  • When @language is declared inside a Stack, it applies to its context

Additive languages​

@language supports additive settings, allowing multiple language paradigms to be enabled simultaneously:

@translateAlias '中文(简体)' print <Value val> -> 输出 <Value val>
@translateAlias 'VarStyle' let <Key name> = <Value val> -> var <Key name> = <Value val>

@language '中文(简体)'
@language 'VarStyle'
~ Chinese and VarStyle keywords can now be used together
输出 '你好'
var count = 1

Translations are applied in declaration order; languages declared later are matched with higher priority.

2. Usage Example​

Translation directives take effect at the parsing stage and must be declared before the code that uses them:

~ Define and enable Chinese keywords
@translateAlias '中文(简体)' let <Key name> = <Value val> -> 使 <Key name> 为 <Value val>
@translateAlias '中文(简体)' new <Key obj> ( <Code args> ) -> 新的 <Key obj> ( <Code args> )
@translateAlias '中文(简体)' print <Value val> -> 打印 <Value val>
@translateClass '中文(简体)' Array [push] -> 列表 [加入]

@language '中文(简体)'

使 示例列表 为 新的 Array []
示例列表.加入 '你好,世界!'
打印 示例列表[0]

3. Supported Translation Types​

Mainstream natural languages​

  • AI can be used for initial translations
  • Official community-assisted translation is open
  • Standard English is provided (natural-language English)

Other keyword systems​

Supported through independent community development, for example:

  • Classical Chinese
  • Kana Japanese
  • Emoji
  • Chinese pinyin
  • Abbreviated keywords for various languages
  • Constructed languages
  • Keywords styled after other programming languages
  • Internet slang
  • Dialects

4. Maintenance Model​

MaintainerResponsibilities
OfficialDirectly maintains the general keywords; maintains mainstream natural language bindings with community assistance
CommunityIndependently collaborates and freely uploads any translation modules to the module repository; may write translation modules for any other modules
ProjectsMay independently maintain multiple sets of their own official translations

5. Project Integration​

ScenarioBehavior
Uploading a project with translationsAutomatically converted to the standard general keywords
Loading an online moduleAutomatically converted to the language declared in the project's config.json
Updating a translation packageFirst converted to general keywords, then to the new version's specific translation

6. The Purpose of the Translation System​

  1. Optimized development experience: lets developers write programs in a familiar language environment without affecting the program's readability
  2. Reduced migration cost: helps newcomers quickly get started with Alia under keyword systems they already know (such as Python)
  3. Beginner-friendly: lets beginners quickly learn and understand Alia's programming approach in their native language

7. Example Code​

~ Comprehensive translation system example

~ 1. Define multi-language translations
@translateAlias '中文(简体)' if <Boolean condition> <Stack stack> -> 如果 <Boolean condition> <Stack stack>
@translateAlias '中文(简体)' else <Stack stack> -> 否则 <Stack stack>
@translateAlias '中文(简体)' let <Key name> = <Value val> -> 设 <Key name> 为 <Value val>
@translateAlias '中文(简体)' print <Value val> -> 输出 <Value val>
@translateAlias '中文(简体)' == -> 等于
@translateClass '中文(简体)' Array [push] -> 列表 [加入]

~ 2. Enable Chinese keywords
@language '中文(简体)'

设 计数 为 0
如果 计数 等于 0 {
输出 '计数为零'
} 否则 {
输出 '计数非零'
}
设 列表 为 []
列表.加入 '第一项'
输出 列表[0]

~ 3. Switch back to the general keywords
@clearLanguage
let count = 0
for { let i = 0 } i < 3 { i ++ } {
print i
count ++
}

~ 4. Additive language example
@translateAlias 'VarStyle' let <Key name> = <Value val> -> var <Key name> = <Value val>
@language '中文(简体)'
@language 'VarStyle'
~ Chinese and VarStyle-style keywords can now be mixed

Next Steps​