XarayaTranslationMemory  1.6
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
TranslationString Class Reference

Public Member Functions

 __construct ($stringID=0, $projectID=0, $original="", $localeID=1, $translation="", $sentenceID=0, $lastSeen=0, $rowOrder=0)
 
 GetStringID ()
 
 GetProjectID ()
 
 GetOriginal ()
 
 GetLocaleID ()
 
 GetTranslation ()
 
 GetSentenceID ()
 
 GetLastSeen ()
 
 SetTranslation ($translation)
 
 SetRowOrder ($index)
 
 Save ()
 
 DestroyData ()
 
 FindSimilar ($FindText="", $localeID=0, $FilterPercent=60)
 
 FindText ($findText="", $localeID=0, $findOriginal, $start=0, $limit=100)
 

Static Public Member Functions

static InitSentenceLengthCache ()
 
static InitWordSentencesCache ()
 

Static Public Attributes

static $SentenceLengthCache
 
static $WordSentencesCache
 

Private Member Functions

 FindSentenceIndex ($findSimilarToo)
 
 StoreSentenceIndex ()
 

Private Attributes

 $StringID
 
 $ProjectID
 
 $Original
 
 $LocaleID
 
 $Translation
 
 $SentenceID
 
 $LastSeen
 
 $RowOrder
 
 $Matches
 
 $Words
 

Detailed Description

Handles one string's data: original string, translation, locale, store new, load stored, etc.

Definition at line 26 of file TranslationString.php.

Constructor & Destructor Documentation

◆ __construct()

TranslationString::__construct (   $stringID = 0,
  $projectID = 0,
  $original = "",
  $localeID = 1,
  $translation = "",
  $sentenceID = 0,
  $lastSeen = 0,
  $rowOrder = 0 
)

Fetch a string from the database or create a new one from passed data.

TranslationString object can be constructed three ways:

$original = "", $stringID > 0: the specified string will be loaded from the database.

$original != "", $stringID > 0: the object instance is initailized with that data as if it was loaded from the database.

$original != "", $stringID = 0: in the way to create a new string with ->Save();

Parameters
$stringIDSpecifies which string to load from the database, 0 if passing all other data!
$projectIDTo which project this string belongs.
$originalThe original language string.
$localeIDThe locale ID of the specified translation.
$translationThe translation of the $original string to $loccaleID locale.
$sentenceIDID of the ($origingal) string in the SentenceIndex table.
$lastSeenUnix timestamp of this string's last insert or update.
$rowOrderThe row order index of this string in its project, see SetRowOrder().
Exceptions:
'Exception' thrown if not existing $StringID is passed for loading from db

Definition at line 65 of file TranslationString.php.

References $DB, GetDbConn(), and GetTables().

Member Function Documentation

◆ DestroyData()

TranslationString::DestroyData ( )

Destroy the currently loaded string in the database, irreversible.

This object will hold the old string's data as if it was a new, not Save()-d one.

Definition at line 365 of file TranslationString.php.

References $DB, GetDbConn(), and GetTables().

◆ FindSentenceIndex()

TranslationString::FindSentenceIndex (   $findSimilarToo)
private

Find similar sentences in the sentence index database

If $findSimilarToo is true the similar sentences will be stored in the internal $this->Matches array. The key is the sentence ID, the value is the match percentage. If $findSimilarToo is false, only one result will be returned, the exact match. $this->Matches remains empty! (Exact match = same words same times, not exactly the same string!)

Parameters
$findSimilarTooIf false, the search will end with the first exact match.

Definition at line 584 of file TranslationString.php.

References $DB, $SentenceLengthCache, GetDbConn(), and GetTables().

Referenced by FindSimilar(), and Save().

◆ FindSimilar()

TranslationString::FindSimilar (   $FindText = "",
  $localeID = 0,
  $FilterPercent = 60 
)

Public function to find existing sentences in the string database

Finds similar sentences and returns them in an array ordered by match percentage descending. Return format: array[stringID]["string"][] = array, TranslationString objects with all matches array[stringID]["percent"] = integer, match percentage If parameters are omitted, the current string object's text and localeID will be used. If parameters are specified, the current string is changed to those.

Parameters
$FindTextThe sentence or text to find, if emtpy, uses this object's Original string.
$localeIDFind strings only in this locale.
$FilterPercentDrop results below this match percentage, defaults to 60.
Returns
Array of matches of ID,Percent subarrays of TranslationStrings, ordered descending by Percent.

Definition at line 396 of file TranslationString.php.

References $DB, $Matches, FindSentenceIndex(), GetDbConn(), and GetTables().

◆ FindText()

TranslationString::FindText (   $findText = "",
  $localeID = 0,
  $findOriginal,
  $start = 0,
  $limit = 100 
)

Find strings based on part of the string.

Can find in both Original string and Translation, uses LIKE string% match for the select. There is no percentage data returned from this function, otherwise the array is the same like in FindSimilar().

Parameters
$findTextThe sentence or text to find, if emtpy, uses this object's Original o Translation.
$localeIDFind strings only in this locale.
$findOriginalbool: true finds in Original strings, false finds in Translations.
$startint: Start at this result entry (for paging).
$limitint: Limit search results to this number.
Returns
Array of matches of ID subarrays of TranslationStrings.

Definition at line 503 of file TranslationString.php.

References $DB, $LocaleID, $Original, $Translation, fixstr(), GetDbConn(), and GetTables().

◆ GetLastSeen()

TranslationString::GetLastSeen ( )

Get the current string's last update timestamp.

Returns
string When the string was last changed or inserted.

Definition at line 231 of file TranslationString.php.

References $LastSeen.

◆ GetLocaleID()

TranslationString::GetLocaleID ( )

Get the current string's locale id.

Returns
int The current string's locale id.

Definition at line 198 of file TranslationString.php.

References $LocaleID.

◆ GetOriginal()

TranslationString::GetOriginal ( )

Get the current string's original (English) text.

Returns
string The current string's original text.

Definition at line 187 of file TranslationString.php.

References $Original.

◆ GetProjectID()

TranslationString::GetProjectID ( )

Get the current string's string project id.

Returns
int The project's id in which this string resides.

Definition at line 176 of file TranslationString.php.

References $ProjectID.

◆ GetSentenceID()

TranslationString::GetSentenceID ( )

Get the current string's sentence index ID, based on what words this string contains.

Returns
string The current string's ID in the sentence index.

Definition at line 220 of file TranslationString.php.

References $SentenceID.

◆ GetStringID()

TranslationString::GetStringID ( )

Get the current string's string id.

Returns
int The current string's string id.

Definition at line 165 of file TranslationString.php.

References $StringID.

◆ GetTranslation()

TranslationString::GetTranslation ( )

Get the current string's translation.

Returns
string The current string's translated text.

Definition at line 209 of file TranslationString.php.

References $Translation.

◆ InitSentenceLengthCache()

static TranslationString::InitSentenceLengthCache ( )
static

Initialize the static sentence cache which contains word counts of each sentence.

The pre-cached wordcounts are used for searching similar things, match percent comparison is based on these numbers, becasue not all words of the SIMILAR strings will be loaded from the database on FindSimilar(), only those words what this searched string also has. Thus complete word-word percent comparsion needs this length data.

Sets TranslationString::$SentenceLengthCache

Definition at line 124 of file TranslationString.php.

References $DB, $SentenceLengthCache, GetDbConn(), and GetTables().

Referenced by CacheIndexes().

◆ InitWordSentencesCache()

static TranslationString::InitWordSentencesCache ( )
static

LATER Initialize the static words sentence cache which contains in which sentences the given word occures.

Definition at line 143 of file TranslationString.php.

References $DB, $WordSentencesCache, GetDbConn(), and GetTables().

◆ Save()

TranslationString::Save ( )

Store the string in the database and create indexes for it.

Checks if the same Original exists in the same Project. In this case no new string created, just updated.

Returns
The found existing or newly created String ID.
Exceptions:
'Exception' thrown if Original srtring is not set.

Definition at line 272 of file TranslationString.php.

References $DB, $SentenceID, $SentenceLengthCache, $StringID, FindSentenceIndex(), GetDbConn(), GetTables(), and StoreSentenceIndex().

◆ SetRowOrder()

TranslationString::SetRowOrder (   $index)

Set the current string's row order index, this will be used for ordering by StringIterators.

Using this value you can make sure, that strings are in good order, even if newer strings in the same project will get much higher StringID in later imports.

Parameters
$indexThe index of this string in its project, for better GUI displays.

Definition at line 255 of file TranslationString.php.

Referenced by TranslationImportXaraya\ImportFile().

◆ SetTranslation()

TranslationString::SetTranslation (   $translation)

Set the current string's translation, call Save() to apply to the database.

Parameters
$translationThe current string's new translated text.

Definition at line 242 of file TranslationString.php.

◆ StoreSentenceIndex()

TranslationString::StoreSentenceIndex ( )
private

Insert the current sentence into the sentence index database

Called by this class after trying FindSentenceIndex for already existing match. If the find did not found a 100% match in the sentence index, this function can be called to add the current sentence.

Definition at line 666 of file TranslationString.php.

References $DB, GetDbConn(), and GetTables().

Referenced by Save().

Member Data Documentation

◆ $LastSeen

TranslationString::$LastSeen
private

The date and time when this string was last updated.

Definition at line 34 of file TranslationString.php.

Referenced by GetLastSeen().

◆ $LocaleID

TranslationString::$LocaleID
private

Language, encoding of this string. Default: HU_hu.utf-8.

Definition at line 31 of file TranslationString.php.

Referenced by FindText(), and GetLocaleID().

◆ $Matches

TranslationString::$Matches
private

Other strings found to be similar, after calling a find!.

Definition at line 37 of file TranslationString.php.

Referenced by FindSimilar().

◆ $Original

TranslationString::$Original
private

The original English string.

Definition at line 30 of file TranslationString.php.

Referenced by FindText(), and GetOriginal().

◆ $ProjectID

TranslationString::$ProjectID
private

The ID of the project to which this string belogns.

Definition at line 29 of file TranslationString.php.

Referenced by GetProjectID().

◆ $RowOrder

TranslationString::$RowOrder
private

The row order index of this string in its project, see SetRowOrder().

Definition at line 35 of file TranslationString.php.

◆ $SentenceID

TranslationString::$SentenceID
private

The ID of this sentence in TranslaitonSentences table.

Definition at line 33 of file TranslationString.php.

Referenced by GetSentenceID(), and Save().

◆ $SentenceLengthCache

TranslationString::$SentenceLengthCache
static

Cache for strings' lengths: InitSentenceLengtCache()

Definition at line 40 of file TranslationString.php.

Referenced by FindSentenceIndex(), InitSentenceLengthCache(), and Save().

◆ $StringID

TranslationString::$StringID
private

ID of this string in TranslationStrings table.

Definition at line 28 of file TranslationString.php.

Referenced by GetStringID(), and Save().

◆ $Translation

TranslationString::$Translation
private

The tranlsation of $Original to $LocaleID.

Definition at line 32 of file TranslationString.php.

Referenced by FindText(), and GetTranslation().

◆ $Words

TranslationString::$Words
private

Contains the ($Original) words of this string

Definition at line 38 of file TranslationString.php.

◆ $WordSentencesCache

TranslationString::$WordSentencesCache
static

LATER Cache for "word in which sentences": InitWordSentencesCache()

Definition at line 41 of file TranslationString.php.

Referenced by InitWordSentencesCache().


The documentation for this class was generated from the following file: