Alphred
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download

Namespaces

  • Alphred
  • None

Classes

  • Alfred
  • AppleScript
  • Choose
  • Config
  • Date
  • Dialog
  • Filter
  • Globals
  • i18n
  • Ini
  • Keychain
  • Log
  • Notification
  • Request
  • Result
  • ScriptFilter
  • Text

Interfaces

  • ConfigKeyNotSet
  • Exception
  • FileDoesNotExist
  • InvalidKeychainAccount
  • InvalidScriptFilterArgument
  • InvalidSecurityAction
  • InvalidXMLProperty
  • PasswordExists
  • PasswordNotFound
  • PluginFunctionNotFound
  • RunningOutsideOfAlfred
  • ShouldBeBool
  • TooManyArguments
  • UnknownSecurityException
  • UseOnlyAsStatic

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.

Namespace: Alphred
Located at i18n.php

Methods summary

public
# __construct( string $engine = 'json' )

Constructs the i18n object to use for translation, setting language

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

$engine
translation utility; json is the only option
public string
# translate( string $string )

Translates a string from a dictionary

Translates a string from a dictionary

Parameters

$string
a string to translate

Returns

string
a, possibly, translated string

Todo

use "engines" instead of a single method

Magic methods summary

Alphred API documentation generated by ApiGen