\Alphredi18n

Translation library for Alphred

Right now, this is sort of "proof-of-concept" and works well enough for static strings, but it does need to be improved vastly.

Right now, the best part about this library is that it will not break anything. So, if you try to implement it and fuck it up, it'll just do nothing rather than break things.

For internationalization:

gettext() isn't compiled into OS X's PHP installation, so I've created my own hacky version.

(1) Create a directory called "i18n" in your workflow folder. (2) For each language you want to use, create a file called ln.json (lowercase) where "ln" is the two-letter language code: i.e. en = English, de = German, etc... (3) In that json, make the original string as the key and the value as the translated test. i.e., a file called i18n/fr.json would contain: { "Hello": "Bonjour", "Do you speak French?": "Parlez-vous Français?", "I am a grapefruit": "Je suis un pamplemousse", }

(4) Make sure you escape the string if necessary.

Tip: if you'd rather have the json created for you, then just do something like... file_put_contents( 'i18n/fr.json', json_encode( [ 'string' => 'translated', 'string2' => 'second translation' ], JSON_PRETTY_PRINT );

Then just execute that PHP, and the json file will be created for you.

Summary

Methods
Properties
Constants
__construct()
translate()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(string  $engine = 'json') 

Constructs the i18n object to use for translation, setting language

Right now $engine is unused, but it's there to open for expansion for other translation methods that can be popped in or out. Json is just what is described above.

Parameters

string $engine

translation utility; json is the only option

translate()

translate(string  $string) : string

Translates a string from a dictionary

Parameters

string $string

a string to translate

Returns

string —

a, possibly, translated string