Skip to content

Latest commit

 

History

History
77 lines (57 loc) · 2.72 KB

fText.wiki

File metadata and controls

77 lines (57 loc) · 2.72 KB

Table of Contents

fText

<<css mode="next" class="sidebar"></css>> (((

Class Resources <<toc></toc>>

 - '''<a href="/docs/fText">Class Documentation</a>'''
 - <a href="/api/fText">API Reference</a>
 - <a href="https://github.com/flourishlib/flourish-classes/blob/master/fText.php" target="_blank">Source Code</a>

<<toc></toc>> )))

The fText class is a static class with the sole purpose of creating a hook to allow for writing internationalized application and localizing Flourish. None of the Flourish classes require it be loaded, but if it is, all message/parameter interpolation is passed through this class.

Composing Messages

The fText class includes a key method to help with the i18n of code. The method ::compose() allows creating a message in multiple pieces that are later interpolated, allowing for efficient translation efforts.

Typically, a call to `compose()` will look like:

which would produce the result:

At its core, `compose()` is simply a wrapper around `sprintf()`. However, being a wrapper allows setting up two hooks for translation. The method ::registerComposeCallback() allows us to intercept any string sent to `compose()` and modify it. The first parameter, `$timing`, allow registering the callback `'pre'` or `'post'` the `sprintf()` call. The second parameter, `$callback`, defines which method to pass the string to.

Any callback registered `pre` will get the un-interpolated string, while any callback registered `post` will get the interpolated string. Here is an example of translation using compose:

The above PHP would output the following:

Localization of Flourish

Every exception and error in Flourish will be passed through ::compose(), thus allowing for localization of the Flourish code base. Please see the MessagesList page for a list of all messages and their location in the source code.