sparrowText

SparrowText is for easy maintaining different translations of texts used by your application.

Summary
sparrowTextSparrowText is for easy maintaining different translations of texts used by your application.
Macros
SP_TEXT_MAX_READABLE_LINEYou shouldn’t have more signs in a line than this value ;-) Nobody will EVER need more than 64k letters in one translation...
Types
spTranslationContains a translation text and the language.
spTextContains different Translation of the same text, which is identified by a caption.
spBundleA bundle is a collection of texts.
Functions
spCreateTextCreates a new text, which contains different translations of the same text.
spAddTranslationAdds a translation to a text.
spCreateTextWithTranslationWorks like a mix of spCreateText and spAddTranslation.
spSearchCaptionFinds a specific spText in a bundle.
spGetTranslationGives you the translation a text in the default language or (if not avaible) in the first added language.
spGetTranslationFromCaptionGives you the translation in the default language of a text.
spCreateTextBundleCreates a text bundle.
spLoadBundleLoads a bundle out of a text file.
spReadPossibleLanguagesReads a “possible languages file”.
spGetPossibleLanguagesCountGets you the total number of all possible languages, if you read them with spReadPossibleLanguages.
spGetPossibleLanguageGives you the language code for a possible language identified by its number.
spGetPossibleLanguageNameGives you the language name for a possible language identified by its number.
spChangeBundleTexts can change their bundles.
spDeleteBundleDeletes a whole bundle.
spSetDefaultLanguageSets the default language of sparrowText.
spDeleteTextDeletes a text.

Macros

SP_TEXT_MAX_READABLE_LINE

You shouldn’t have more signs in a line than this value ;-) Nobody will EVER need more than 64k letters in one translation...

Types

spTranslation

Contains a translation text and the language.

Variables

text (char*)a text in some language
language (Uint16)the language of the text above
next (spTranslation*)needed for the internal linked list.  Do not change

spText

Contains different Translation of the same text, which is identified by a caption.  The captions should be unique in bundles (See spBundle).

Variables

caption (char*)name of the text
firstTranslation (spTranslation*)start of a linked list of possible translations
bundle (spBundle*)bundle of the text
prev,next (spText*)internal double linked list variables for the bundle.  Do not change

spBundle

A bundle is a collection of texts.  Every text is in exactly one bunch.

Variables

firstText (spText*)start of a double linked list of the texts
next (spBundle*)internal pointer to the next bundle in a linked list.  Do not use or change!

Functions

spCreateText

PREFIX spTextPointer spCreateText(const char *caption,
spBundlePointer bundle)

Creates a new text, which contains different translations of the same text.

Parameters

captionthe name of this text
bundleoptional bundle to add this text to.  If no bundle is given, the text will be added to the internal global bundle

Returns

spText*pointer to the created spText struct

See Also

spCreateTextWithTranslation

spAddTranslation

PREFIX void spAddTranslation(spTextPointer text,
Uint16 language,
const char *translation)

Adds a translation to a text.

Parameters

textpointer to a spText struct, to which the translation shall be added
languageUint16 language number of the added translation
translationthe text of the translation

See Also

spCreateTextWithTranslation

spCreateTextWithTranslation

PREFIX spTextPointer spCreateTextWithTranslation(const char *caption,
spBundlePointer bundle,
Uint16 language,
const char *translation)

Works like a mix of spCreateText and spAddTranslation.  It creates a text and adds a first translation to it.

Parameters

captionthe name of this text
bundleoptional bundle to add this text to.  If no bundle is given, the text will be added to the internal global bundle
languageUint16 language number of the added translation
translationthe text of the translation

Returns

spText*pointer to the created spText struct

See Also

spCreateText, spAddTranslation

spSearchCaption

PREFIX spTextPointer spSearchCaption(spBundlePointer bundle,
char *caption)

Finds a specific spText in a bundle.  Attention!  This function is relative slow.  If you have much text, try to mind the returned pointer.

Parameters

bundlethe bundle, in which the function shall search.  If the text is in the internal global bundel, pass NULL
captionthe caption of the text to find

Returns

spText*a pointer of the found spText or NULL if nothing was found

See Also

spGetTranslationFromCaption

spGetTranslation

PREFIX char* spGetTranslation(spTextPointer text)

Gives you the translation a text in the default language or (if not avaible) in the first added language.  That is the reason, why it makes sense, to add Englisch first everytime!

Parameters

texta pointer to a spText struct, from which you want the right translation

Returns

char*the translation as null terminated string

See Also

spGetTranslationFromCaption

spGetTranslationFromCaption

PREFIX char* spGetTranslationFromCaption(spBundlePointer bundle,
char *caption)

Gives you the translation in the default language of a text.

Parameters

bundlethe bundle, in which shall be searched
captionthe caption of the text

Returns

char*the translation as null terminated string.  However, if the language is not found, but the caption, the first definied language is returned.  If the caption is not found an error string is returned.

See Also

spGetTranslation, spSearchCaption

spCreateTextBundle

PREFIX spBundlePointer spCreateTextBundle(void)

Creates a text bundle.  Bundles are very practical for encapsuling texts of different kinds.  However: If you don’t need them and always refer to bundle “NULL”, the undeletable internal main bundle of sparrowText is used.

Returns

spBundle*pointer to the created bundle

spLoadBundle

PREFIX spBundlePointer spLoadBundle(const char *filename,
int own_bundle)

Loads a bundle out of a text file.  The files are like ini-files and the interpretation of one line depends on the beginning.  There are 3 kinds of beginning a line:

  • ”#” starts a comment
  • ”--” followed by a random sign (like “ “ or “:”) and followed by any string defines a new spText with the caption of the given string
  • ”XX” followed by a random sign (like “ “ or “:”) and followed by any string defines a new translation of the language “XX”, which can be any language of the ISO 639-1, e.g.  “de” or “en”, which is added to the LAST defined text.  Example:
# this is a comment.
--:example text
en This is an example text.
de Das ist ein Beispieltext
la lorem ipsum ;-)

Parameters

filenamefile to read
own_bundlePass 1 to create an own bundle or 0 to add the loaded translations to the internal main bundle

Returns

spBundle*pointer to the spBundle struct the translations are added in

spReadPossibleLanguages

PREFIX void spReadPossibleLanguages(const char *filename)

Reads a “possible languages file”.  In fact it is the same like the bundle files explained in spLoadBundle, but there is just one “text” defined and this text HAVE to be named “languages”.  The following defined translations are the possible languages and their names.  Example:

--:languages
en:English
de:Deutsch
la:Latinus

Parameters

filenamefile with possible languages to read

See Also

spGetPossibleLanguage, spGetPossibleLanguageName, spGetPossibleLanguagesCount

spGetPossibleLanguagesCount

PREFIX int spGetPossibleLanguagesCount(void)

Gets you the total number of all possible languages, if you read them with spReadPossibleLanguages.

Returns

intthe number of possible languages

See Also

spReadPossibleLanguages, spGetPossibleLanguage, spGetPossibleLanguageName

spGetPossibleLanguage

PREFIX Uint16 spGetPossibleLanguage(int nr)

Gives you the language code for a possible language identified by its number.

Parameters

nrthe number of the language

Returns

Uint16the language code

See Also

spReadPossibleLanguages, spGetPossibleLanguagesCount, spGetPossibleLanguageName

spGetPossibleLanguageName

PREFIX char* spGetPossibleLanguageName(int nr)

Gives you the language name for a possible language identified by its number.

Parameters

nrthe number of the language

Returns

char*name of the language

See Also

spReadPossibleLanguages, spGetPossibleLanguagesCount, spGetPossibleLanguage

spChangeBundle

PREFIX void spChangeBundle(spTextPointer text,
spBundlePointer bundle)

Texts can change their bundles.  Do it with this function ;-)

Parameters

textthe text to change it’s bundle
bundlethe new bundle of the text.  Can be NULL, then the text is added to the global main internal bundle

spDeleteBundle

PREFIX void spDeleteBundle(spBundlePointer bundle,
int keepText)

Deletes a whole bundle.

Parameters

bundlebundle to deleted
keepTextif 1, no text well be deleted and the bundle of the texts will be the internal main bundle (which will be searched, if you pass “NULL” as bunch parameter), else the texts are deleted, too.  Obviously
spDeleteBundle(NULL,1);

doesn’t make sense.  But of course you can use it to clean the main bundle with

spDeleteBundle(NULL,0);

spSetDefaultLanguage

PREFIX void spSetDefaultLanguage(Uint16 language)

Sets the default language of sparrowText.  The default language is Englisch (en).

Parameters

languageUint16 code of the new default language

spDeleteText

PREFIX void spDeleteText(spTextPointer text)

Deletes a text.

Parameters

texttext to be deleted.  It is also removed from it’s bundle of course.
PREFIX spTextPointer spCreateText(const char *caption,
spBundlePointer bundle)
Creates a new text, which contains different translations of the same text.
PREFIX void spAddTranslation(spTextPointer text,
Uint16 language,
const char *translation)
Adds a translation to a text.
PREFIX spTextPointer spCreateTextWithTranslation(const char *caption,
spBundlePointer bundle,
Uint16 language,
const char *translation)
Works like a mix of spCreateText and spAddTranslation.
PREFIX spTextPointer spSearchCaption(spBundlePointer bundle,
char *caption)
Finds a specific spText in a bundle.
Contains different Translation of the same text, which is identified by a caption.
PREFIX char* spGetTranslation(spTextPointer text)
Gives you the translation a text in the default language or (if not avaible) in the first added language.
PREFIX char* spGetTranslationFromCaption(spBundlePointer bundle,
char *caption)
Gives you the translation in the default language of a text.
PREFIX spBundlePointer spCreateTextBundle(void)
Creates a text bundle.
PREFIX spBundlePointer spLoadBundle(const char *filename,
int own_bundle)
Loads a bundle out of a text file.
PREFIX void spReadPossibleLanguages(const char *filename)
Reads a “possible languages file”.
PREFIX int spGetPossibleLanguagesCount(void)
Gets you the total number of all possible languages, if you read them with spReadPossibleLanguages.
PREFIX Uint16 spGetPossibleLanguage(int nr)
Gives you the language code for a possible language identified by its number.
PREFIX char* spGetPossibleLanguageName(int nr)
Gives you the language name for a possible language identified by its number.
PREFIX void spChangeBundle(spTextPointer text,
spBundlePointer bundle)
Texts can change their bundles.
PREFIX void spDeleteBundle(spBundlePointer bundle,
int keepText)
Deletes a whole bundle.
PREFIX void spSetDefaultLanguage(Uint16 language)
Sets the default language of sparrowText.
PREFIX void spDeleteText(spTextPointer text)
Deletes a text.
A bundle is a collection of texts.
Close