Format class used to support NGX Translate JSON file format.

since 3.0.0
package GlotPress
inherited_from \GP_Format

 Methods

Gets the list of supported file extensions.

get_file_extensions() : array
Inherited
since 2.0.0

Returns

arraySupported file extensions.

Generates a string the contains the $entries to export in the JSON file format.

print_exported_file(\GP_Project $project, \GP_Locale $locale, \GP_Translation_Set $translation_set, \GP_Translation $entries) : string
since 3.0.0
inherited_from \GP_Format::print_exported_file()

Parameters

$project

\GP_Project

The project the strings are being exported for, not used in this format but part of the scaffold of the parent object.

$locale

\GP_Locale

The locale object the strings are being exported for. not used in this format but part of the scaffold of the parent object.

$translation_set

\GP_Translation_Set

The locale object the strings are being exported for. not used in this format but part of the scaffold of the parent object.

$entries

\GP_Translation

The entries to export.

Returns

stringThe exported JSON string.

print_exported_file()

print_exported_file($project, $locale, $translation_set, $entries) 
Inherited

Parameters

$project

$locale

$translation_set

$entries

Reads a set of original strings from a JSON file.

read_originals_from_file(string $file_name) : \Translations | boolean
since 3.0.0
inherited_from \GP_Format::read_originals_from_file()

Parameters

$file_name

string

The name of the uploaded JSON file.

Returns

\TranslationsbooleanThe extracted originals on success, false on failure.

read_originals_from_file()

read_originals_from_file($file_name) 
Inherited

Parameters

$file_name

read_translations_from_file()

read_translations_from_file($file_name, $project = null
Inherited

Parameters

$file_name

$project

Decode a JSON file.

decode_json_file(string $file_name) : \decode
since 3.0.0

Parameters

$file_name

string

The name of the JSON file to decode.

Returns

\decodeJSON file as an array.

Create a string that represents the value for the "Language:" header for an export file.

get_language_code(\GP_Locale $locale) : string | false
Inherited
since 2.1.0

Parameters

$locale

\GP_Locale

The locale object.

Returns

stringfalseReturns false if the locale object does not have any iso_639 language code, otherwise returns the shortest possible language code string.

 Properties

 

$alt_extensions

$alt_extensions 

Default

array()
 

File extension of the file format, used to autodetect formats and when creating the output file names.

$extension : string

Default

'ngx.json'
since 3.0.0
inherited_from \GP_Format::extension
 

$extension

$extension 

Default

''
 

$filename_pattern

$filename_pattern 

Default

'%s-%s'
 

Name of file format, used in file format dropdowns.

$name : string

Default

'NGX-Translate (.json)'
since 3.0.0
inherited_from \GP_Format::name
 

$name

$name 

Default

''