\TransvisionShowResults

ShowResults class

This class is used to get search results and display them

Summary

Methods
Properties
Constants
getTMXResults()
getSuggestionsResults()
getTranslationMemoryResults()
getTransliteratedString()
getRepositorySearchResults()
getStringFromEntity()
formatEntity()
getEditLink()
resultsTable()
searchEntities()
buildErrorString()
buildComponentsFilter()
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

getTMXResults()

getTMXResults(array  $entities, array  $array_strings) : array

Create an array for search results with this format: 'entity' => ['string_locale 1', 'string_locale 2']

Parameters

array $entities

Haystack of entities to search in

array $array_strings

The strings to look into [locale1 strings, locale2 strings]

Returns

array —

Results with entities as keys and translations as values

getSuggestionsResults()

getSuggestionsResults(array  $source_strings, array  $target_strings, string  $search, integer  $max_results = 10) : array

Return an array of suggestions from our Translation Memory API. Unlike other services, we return values from both source and target languages.

Parameters

array $source_strings

Matches from source strings

array $target_strings

Matches from target strings

string $search

The string to search for

integer $max_results

Optional, default to 10, the max number of results we return

Returns

array —

An array of strings

getTranslationMemoryResults()

getTranslationMemoryResults(array  $strings, string  $search, integer  $max_results = 200, integer  $min_quality) : array

Return an array of search results from our Translation Memory API service with a quality index based on the levenshtein distance.

Parameters

array $strings

The source and target strings to look into

string $search

The string to search for

integer $max_results

Optional, default to 200, the max number of results we return

integer $min_quality

Optional, default to 0, The minimal quality index to filter result

Returns

array —

An array of strings as [source => string, target => string, quality=> Levenshtein index]

getTransliteratedString()

getTransliteratedString(string  $string, string  $locale) : string

Use the API to return a transliterated string

Parameters

string $string

The string to be transliterated

string $locale

The target locale

Returns

string —

The string transliterated into the target locale

getRepositorySearchResults()

getRepositorySearchResults(array  $entities, array  $array_strings) : array

Return search results in a repository on strings/entities for the API

Parameters

array $entities

An array of all the entities we want to return

array $array_strings

The strings to look into [locale1 strings, locale2 strings]

Returns

array —

An array of strings with the entity as key [entity => [English => French]]

getStringFromEntity()

getStringFromEntity(string  $entity, array  $strings) : string

Returns the string from its entity or false

Parameters

string $entity

Entity we are looking for

array $strings

Haystack of strings to search in

Returns

string —

The string for the entity or false if no matching result

formatEntity()

formatEntity(string  $entity, boolean  $highlight = false) : string

Nicely format entities for tables by splitting them in subpaths and styling them

Parameters

string $entity
boolean $highlight

Optional. Default to false. Use a highlighting style

Returns

string —

Entity reformated with html markup and css classes for styling

getEditLink()

getEditLink(string  $tool, string  $repo, string  $key, string  $text, string  $locale) : string

Return link to edit a message on external tool used by requested locale

Parameters

string $tool

Tool name

string $repo

Repository

string $key

Key of the current string

string $text

Text of the current strings

string $locale

Current locale

Returns

string —

HTML link to edit the string inside the tool used by this locale

resultsTable()

resultsTable(object  $search_object, object  $search_id, array  $search_results, string  $page) : string

Html table of search results used by the main view (needs a lot of refactoring)

Parameters

object $search_object

The Search object that contains all the options for the query

object $search_id

Search ID

array $search_results

List of rows

string $page

The page we are generating, used to output results for 2 or 3 locales

Returns

string —

html table to insert in the view

searchEntities()

searchEntities(array  $source_strings, string  $regex) : array

Search entity names: search full entity IDs (including path and filename), then search entity names (without the full path) if there are no results.

Parameters

array $source_strings

Array of source strings

string $regex

Regular expression to search entity names

Returns

array —

List of matching entity names

buildErrorString()

buildErrorString(string  $source_string, string  $target_string) : string

Build the error message for target string. Can return a combination of errors, including missing final dot, long string and short string.

Parameters

string $source_string

String from the source locale

string $target_string

String from the target locale

Returns

string —

A concatenated string of errors or an empty string if there is no error.

buildComponentsFilter()

buildComponentsFilter(array  $components) : string

Build HTML fragment for components filter.

Parameters

array $components

List of components

Returns

string —

HTML for components filter