A behavior to automatically parse the software for translation calls on text,
add that text to our translation files, consolidate duplicate entries into
common.php, and then translate all missing entries via Google Translate API. To
run the translation automation, navigate to "admin/automateTranslation" in the
software. End users should never need to run this code (and in fact without the
Google API Key file and Google Translation Billing API configured it will not
work). This class is primarily designed for developer use to update translations
for new releases.
Methods summary
public
string
|
#
getRegex( string $allowedChars = "(){}_.-,+^%@*#|&!?/<>;:" )
The regular expression for matching calls to Yii::t
The regular expression for matching calls to Yii::t
See protected/tests/data/messageparser/modules1.php for examples of what will
be matched by this pattern.
Parameters
- $allowedChars
string $allowedChars valid special characters to match inside of translation calls
Returns
string the constructed regex pattern
|
public
|
#
addMissingTranslations( )
Add missing translations to files, first step of automation.
Add missing translations to files, first step of automation.
Function to find all untralsated text in the software, and then take that
array of messages and add them to translation files for all languages. Called in
X2TranslationAction::run function as part of the full translation
suite.
|
public
|
|
public
string|boolean
|
#
getTranslationFileName( string $modelName )
Converts model name to translation file name.
Converts model name to translation file name.
Helper method called in X2TranslationBehavior::getMessageList() to find the correct
translation file for a model. This is necessary because some models have class
names like Quote or Opportunity but their file names are quotes and
opportunities.
Parameters
- $modelName
string $modelName The name of the model to look up the related translation file for.
Returns
string|boolean Returns the name of the translation file to use, or false if a correct file
cannot be found.
|
public
array
|
#
fileList( string $revision = null )
Parse file structure for valid files.
Parse file structure for valid files.
Returns a list of all files in the codebase that are eligible for searching
for Yii::t calls within.
Parameters
- $revision
string $revision Unused, may implement comparison between Git revisions rather than
searching all files.
Returns
array List of files to be parsed for Yii::t calls
|
public
boolean
|
#
excludePath( string $relPath )
Returns true or false based on whether a path should be parsed for
messages.
Returns true or false based on whether a path should be parsed for
messages.
Some files in the software don't need to be translated. Yii provides all of
its own translations for the framework directory, and there are other files
which simply have no possibility of having Yii::t calls in them. Ignoring these
files speeds up the process, especially since framework is a very large
directory.
Parameters
- $relPath
string $relPath Paths to folders which should not be included in the Yii::t search
Returns
boolean True if file should be excluded from the search, false if the file is OK.
|
public
array
|
#
getMessageList( mixed $file )
Gets a list of Yii::t calls.
Gets a list of Yii::t calls.
Helper function called by X2TranslationBehavior::addMissingTranslations() to get a list of
messages found in Yii::t calls found in the software in an easily parsed array
format. Also checks attribute labels of non-custom modules in the x2_fields
table.
Returns
array An array of messages found in the software that need to be added to the
translation files.
|
public
array
|
#
parseFile( string $path )
Return Yii::t calls in a specific file
Return Yii::t calls in a specific file
Helper method called in X2TranslationBehavior::getMessageList() Parses a file and returns an
associative array of module names to messages for that file.
Parameters
- $path
string $path Filepath to the file to be checked by the REGEX
Returns
array An array of messages in Yii::t calls in the provided file.
|
public
|
|
public
|
#
addMessages( type $file, type $messageList, mixed $common = null )
Commented out until unit test is built.
Commented out until unit test is built.
Parameters
- $file
type $file
- $messageList
type $messageList
- $common
|
public
|
#
consolidateMessages( )
Move commonly used phrases to common.php, second step of automation.
Move commonly used phrases to common.php, second step of automation.
Function that parses translation files for all languages and consolidates
them. First it builds a list of redundancies between files, then loops through
that array, adding redundant phrases to common.php and removing them from their
original files. This means any given word/phrase in the software only needs to
be translated once. Called in X2TranslationAction::run function as part
of the full translation suite.
|
public
|
#
buildRedundancyList( )
Get redundant translations to be merged into common.php
Get redundant translations to be merged into common.php
Helper function called by {@link consolidateMessages) to build a list of
files that have redundant messages in them, as well as a list of what those
messages are. Loads this data into the property $this->intersect;
|
public
|
#
addToCommon( string $message )
Add a message to common.php for all languages
Add a message to common.php for all languages
Helper function called by X2TranslationBehavior::consolidateMessages() to add a redundant
message into common.php. The message will nto be added if it already exists in
common.
Parameters
- $message
string $message The message to be added to common.php
|
public
|
#
removeMessage( string $file, string $message )
Deletes a message from a language file in all languages.
Deletes a message from a language file in all languages.
Called as a part of the consolidation process to remove redundant messages
from the files they were found in. This keeps the amount of messages lower and
reduced the burden on anyone who is translating the software.
Parameters
- $file
string $file The name of the file to look for the message in
- $message
string $message The message to be removed
|
public
|
#
updateTranslations( )
Call Google Translate API for mising translations, third step of
automation.
Call Google Translate API for mising translations, third step of
automation.
This method will get a list of all messages which do not have translations
into the appropriate language from all of our language files. Then, it will call
Google Translate's API to get a base translation of the message and insert the
translated versions into our translation files. Called in X2TranslationAction::run function as part of the full translation suite.
|
public
array
|
#
getUntranslatedText( )
Get all untranslated messages
Get all untranslated messages
Helper function called by X2TranslationBehavior::updateTranslations() to get an array of all
messages which have indeces in the translation files but no translated
version.
Returns
array A list of all messages which have missing translations.
|
public
string
|
#
translateMessage( string $message, string $lang )
Translate a message via Google Translate API.
Translate a message via Google Translate API.
Helper function called by X2TranslationBehavior::updateTranslations() to translate individual
messages via the Google Translate API. Any text between braces {} is preserved
as is for variable replacement.
Parameters
- $message
string $message The untranslated message
- $lang
string $lang The language to translate to
Returns
string The translated message
|
public
|
|
public
|
|
public
|
#
replaceTranslations( string $lang, string $file, array $translations )
Add translated messages to translation files.
Add translated messages to translation files.
Helper function called by X2TranslationBehavior::updateTranslations() to replace the
untranslated messages in a translation file with the response we got from
Google.
Parameters
- $lang
string $lang The language we translated our messages to
- $file
string $file The file we need to put the translations in
- $translations
array $translations An array of translations with the English message as the index and
the translated version as the value.
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
Methods inherited from CComponent
__call(),
__get(),
__isset(),
__set(),
__unset(),
asa(),
attachBehavior(),
attachBehaviors(),
attachEventHandler(),
canGetProperty(),
canSetProperty(),
detachBehavior(),
detachBehaviors(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
getEventHandlers(),
hasEvent(),
hasEventHandler(),
hasProperty(),
raiseEvent()
|