Class i18n
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.
Methods summary
public
|
#
__construct( string $engine = 'json' )
Constructs the i18n object to use for translation, setting language |
public
string
|