Skip to content

Simple Example

This is just meant to give you a general idea.

More details can be found in the documentation sections for developers and authors & translators.

Our Grammar Engine is written in an as-intuitive way as possible. Adding it to any existing or new project is very easy and straight-forward. Original content creators and translators can pick up and effectively use the Grammar Engine within a very short time frame.

The Grammar Engine supports two distinctive use cases:

  • Variables can be inserted into templated texts with placeholders while following the individual language's grammatical rules, such as using the correct articles or declension based on gender, count, or grammatical case.

  • Segments and components, such as nouns and adjectives, can be combined to form new terms to be used as variables for placeholder texts. Proper declension is applied to create naturally sounding names, while not forcing translators into any fixed naming or order structure.

Note on Examples

The following code snippets are meant to showcase the basic usage of the library and how easy it is to be used. Individual syntax details might depend based on your target platform, library type, version, etc.

Placeholder Usage

This short example demonstrates the simplicity of using the Grammar Engine to utilize placeholder texts.

More details can be found in the sections for developers and authors & translators.

Developer's Perspective

While the actual syntax depends on the programming language being used, implementing calls to the Lingoona Grammar Engine is generally quick and straightfoward. The following example uses the direct C/C++ interface.

// temporary buffer used for transformation
wchar_t buffer[256];

// Setting named variables
grammar::setVar(L"attacker", GetString("TEXT_PLAYER_NAME"));
grammar::setVar(L"victim", GetString("TEXT_SOME_ENEMY"));

// Copying the text template
wcscpy(buffer, GetString("TEXT_KILL_MESSAGE"));

// Processing the text template and returning the result
grammar::useGrammar(buffer, 256);

The code for the shared/plugin interface looks similar:

// Setting named variables
Grammar.setVar("attacker", GetString("TEXT_PLAYER_NAME"));
Grammar.setVar("victim", GetString("TEXT_SOME_ENEMY"));

// Processing the text template and returning the result
string result = Grammar.useGrammar(GetString("TEXT_KILL_MESSAGE"));

Content Creator's Perspective

To create a simple "kill message", a content creator could use the following text:

# English
TEXT_KILL_MESSAGE = The <<attacker>> has slain the <<victim>>.
TEXT_PLAYER_NAME  = Eric^M
TEXT_SOME_ENEMY   = hairy spider

The two placeholders in the message will later on be filled with the respective variable contents.

Note the special tag behind "Eric". This is used to denote "Eric" as a male proper name.

As you can see, the content creator (and later on the translators) don't have to worry about any implementation details or potential problematic edge cases (such as having to skip an article).

Easy to Learn

The tagging system might feel daunting at first, but the list of available tags to learn and remember is comparatively low and defined as intuitive as possible. You'll typically only tag variables. Placeholder tagging is only required for edge cases.

Translator's Perspective

For translators, this whole process is pretty much the same. They'll have their source text and translate it to their own language, using the male singular form for articles.

# German
TEXT_KILL_MESSAGE = Der <<attacker>> hat den <<victim>> erschlagen.
TEXT_PLAYER_NAME  = Erik^M
TEXT_SOME_ENEMY   = haarige Spinne^f

Gender Tagging

In this German example, the hairy spider also needs a tag, because German has to use proper declension based on a noun's gender.

Easy to Learn

The tagging system might feel daunting at first, but the list of available tags to learn and remember is comparatively low and defined as intuitive as possible. You'll typically only tag variables. Placeholder tagging is only required for edge cases.

Grammar Engine Results

Once the Grammar Engine read the passed placeholder text, said placeholders will be replaced with the specified variable contents. Depending on how the placeholders have been used, e.g. following an article or pronoun, the variable contents will be adjusted accordingly, the article or pronoun will be replaced or removed, and the final result returned.

Given the example above, the English version would result in a simple but natural sentence:

Eric has slain the hairy spider.

Far more complex, yet similar correct, is the German version, using proper articles and declension:

Erik hat die haarige Spinne erschlagen.

Name Generator Usage

This simple example is supposed to showcase you the simplicity of using the Grammar Engine to generate names on the fly.

More details be found in the Developers and Authors & Translators menus above.

Programmer's Perspective

While the actual syntax depends on the programming language being used, implementing calls to the Lingoona Grammar Engine is generally quick and straightfoward. The following example uses the C/C++ interface.

// Temporary buffer used for transformation
wchar_t buffer[256];

// Copying the noun as a starting point
wcscpy(buffer, GetString("ITEM_SWORD"));

// Updating the buffer by concatenating the name
grammar::generateName(buffer, 256, 2, GetString("QUALITY_LOW"), GetString("MATERIAL_IRON"));

The code for the shared/plugin interface looks similar:

// Preparing the affixes in an array
string[] affixes = new string[] { GetString("QUALITY_LOW"), GetString("MATERIAL_IRON") };

// Generating the item name with these affixes based on a specific noun
string result = Grammar.generateName(GetString("ITEM_SWORD"), affixes);

Content Creator's Perspective

The content creator defines the components making up names. Optional tags tell the library how to handle these components (i.e. where and how to place them).

# English
ITEM_SWORD    = sword^n
QUALITY_LOW   = worn^a
MATERIAL_IRON = iron^a

Easy to Learn

The tagging system might feel daunting at first, but the list of available tags to learn and remember is comparatively low and defined as intuitive as possible. You'll typically only add one tag for gender or position.

Translator's Perspective

For translators this is once again essentially the same. They're free to reinterpret single components by adjusting the tags as they see fit, without any modifications being done by programmers or original content creators.

# French
ITEM_SWORD    = épée^f
QUALITY_LOW   = usé^z
MATERIAL_IRON = en fer^z

# German
ITEM_SWORD    = Schwert^n
QUALITY_LOW   = gebrauchter^a
MATERIAL_IRON = Eisen^+

Easy to Learn

The tagging system might feel daunting at first, but the list of available tags to learn and remember is comparatively low and defined as intuitive as possible. You'll typically only add one tag for gender or position.

Grammar Engine Results

Once the Grammar Engine read the passed noun, it will be expanded using the specified components. Depending on how the components have been marked, e.g. as a prefix or suffix, they're adjusted, if needed, and concatenated to the original noun. The final result is then returned and may be used as variable content in placeholder text.

Given the example above, the generated English word will be returned as expected, tagged with the proper gender in addition:

worn iron sword^n

The French version is concatenated in a similar way, yet this time both affixes are appended to the end and the quality suffix is declined (female form):

épée en fer usée^f

German uses yet another way to concatenate this, by directly attaching the material to the base noun. In addition, the adjective is declined since the German term "Schwert" is neuter:

gebrauchtes Eisenschwert^n


Last update: January 7, 2020