@@ -24,32 +24,32 @@ |
||
24 | 24 | /** |
25 | 25 | * {@parentDoc}. |
26 | 26 | */ |
27 | - public static function toString(Translations $translations, array $options = []) |
|
27 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
28 | 28 | { |
29 | 29 | $options += static::$options; |
30 | - $handle = fopen('php://memory', 'w'); |
|
30 | + $handle = fopen( 'php://memory', 'w' ); |
|
31 | 31 | |
32 | - if ($options['includeHeaders']) { |
|
33 | - static::fputcsv($handle, ['', '', static::generateHeaders($translations)], $options); |
|
32 | + if ( $options[ 'includeHeaders' ] ) { |
|
33 | + static::fputcsv( $handle, [ '', '', static::generateHeaders( $translations ) ], $options ); |
|
34 | 34 | } |
35 | 35 | |
36 | - foreach ($translations as $translation) { |
|
37 | - if ($translation->isDisabled()) { |
|
36 | + foreach ( $translations as $translation ) { |
|
37 | + if ( $translation->isDisabled() ) { |
|
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | |
41 | - $line = [$translation->getContext(), $translation->getOriginal(), $translation->getTranslation()]; |
|
41 | + $line = [ $translation->getContext(), $translation->getOriginal(), $translation->getTranslation() ]; |
|
42 | 42 | |
43 | - if ($translation->hasPluralTranslations(true)) { |
|
44 | - $line = array_merge($line, $translation->getPluralTranslations()); |
|
43 | + if ( $translation->hasPluralTranslations( true ) ) { |
|
44 | + $line = array_merge( $line, $translation->getPluralTranslations() ); |
|
45 | 45 | } |
46 | 46 | |
47 | - static::fputcsv($handle, $line, $options); |
|
47 | + static::fputcsv( $handle, $line, $options ); |
|
48 | 48 | } |
49 | 49 | |
50 | - rewind($handle); |
|
51 | - $csv = stream_get_contents($handle); |
|
52 | - fclose($handle); |
|
50 | + rewind( $handle ); |
|
51 | + $csv = stream_get_contents( $handle ); |
|
52 | + fclose( $handle ); |
|
53 | 53 | |
54 | 54 | return $csv; |
55 | 55 | } |
@@ -17,10 +17,10 @@ |
||
17 | 17 | /** |
18 | 18 | * {@parentDoc}. |
19 | 19 | */ |
20 | - public static function toString(Translations $translations, array $options = []) |
|
20 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
21 | 21 | { |
22 | 22 | $options += static::$options; |
23 | 23 | |
24 | - return json_encode(static::toArray($translations, $options['includeHeaders']), $options['json']); |
|
24 | + return json_encode( static::toArray( $translations, $options[ 'includeHeaders' ] ), $options[ 'json' ] ); |
|
25 | 25 | } |
26 | 26 | } |
@@ -16,117 +16,117 @@ |
||
16 | 16 | /** |
17 | 17 | * {@parentDoc}. |
18 | 18 | */ |
19 | - public static function toString(Translations $translations, array $options = []) |
|
19 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
20 | 20 | { |
21 | 21 | $options += static::$options; |
22 | - $messages = []; |
|
22 | + $messages = [ ]; |
|
23 | 23 | |
24 | - if ($options['includeHeaders']) { |
|
25 | - $messages[''] = static::generateHeaders($translations); |
|
24 | + if ( $options[ 'includeHeaders' ] ) { |
|
25 | + $messages[ '' ] = static::generateHeaders( $translations ); |
|
26 | 26 | } |
27 | 27 | |
28 | - foreach ($translations as $translation) { |
|
29 | - if (!$translation->hasTranslation() || $translation->isDisabled()) { |
|
28 | + foreach ( $translations as $translation ) { |
|
29 | + if ( ! $translation->hasTranslation() || $translation->isDisabled() ) { |
|
30 | 30 | continue; |
31 | 31 | } |
32 | 32 | |
33 | - if ($translation->hasContext()) { |
|
34 | - $originalString = $translation->getContext()."\x04".$translation->getOriginal(); |
|
33 | + if ( $translation->hasContext() ) { |
|
34 | + $originalString = $translation->getContext() . "\x04" . $translation->getOriginal(); |
|
35 | 35 | } else { |
36 | 36 | $originalString = $translation->getOriginal(); |
37 | 37 | } |
38 | 38 | |
39 | - $messages[$originalString] = $translation; |
|
39 | + $messages[ $originalString ] = $translation; |
|
40 | 40 | } |
41 | 41 | |
42 | - ksort($messages); |
|
43 | - $numEntries = count($messages); |
|
42 | + ksort( $messages ); |
|
43 | + $numEntries = count( $messages ); |
|
44 | 44 | $originalsTable = ''; |
45 | 45 | $translationsTable = ''; |
46 | - $originalsIndex = []; |
|
47 | - $translationsIndex = []; |
|
46 | + $originalsIndex = [ ]; |
|
47 | + $translationsIndex = [ ]; |
|
48 | 48 | $pluralForm = $translations->getPluralForms(); |
49 | - $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
|
49 | + $pluralSize = is_array( $pluralForm ) ? ( $pluralForm[ 0 ] - 1 ) : null; |
|
50 | 50 | |
51 | - foreach ($messages as $originalString => $translation) { |
|
52 | - if (is_string($translation)) { |
|
51 | + foreach ( $messages as $originalString => $translation ) { |
|
52 | + if ( is_string( $translation ) ) { |
|
53 | 53 | // Headers |
54 | 54 | $translationString = $translation; |
55 | 55 | } else { |
56 | 56 | /* @var $translation \Gettext\Translation */ |
57 | - if ($translation->hasPlural() && $translation->hasPluralTranslations(true)) { |
|
58 | - $originalString .= "\x00".$translation->getPlural(); |
|
57 | + if ( $translation->hasPlural() && $translation->hasPluralTranslations( true ) ) { |
|
58 | + $originalString .= "\x00" . $translation->getPlural(); |
|
59 | 59 | $translationString = $translation->getTranslation(); |
60 | - $translationString .= "\x00".implode("\x00", $translation->getPluralTranslations($pluralSize)); |
|
60 | + $translationString .= "\x00" . implode( "\x00", $translation->getPluralTranslations( $pluralSize ) ); |
|
61 | 61 | } else { |
62 | 62 | $translationString = $translation->getTranslation(); |
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | - $originalsIndex[] = [ |
|
67 | - 'relativeOffset' => strlen($originalsTable), |
|
68 | - 'length' => strlen($originalString) |
|
66 | + $originalsIndex[ ] = [ |
|
67 | + 'relativeOffset' => strlen( $originalsTable ), |
|
68 | + 'length' => strlen( $originalString ) |
|
69 | 69 | ]; |
70 | - $originalsTable .= $originalString."\x00"; |
|
71 | - $translationsIndex[] = [ |
|
72 | - 'relativeOffset' => strlen($translationsTable), |
|
73 | - 'length' => strlen($translationString) |
|
70 | + $originalsTable .= $originalString . "\x00"; |
|
71 | + $translationsIndex[ ] = [ |
|
72 | + 'relativeOffset' => strlen( $translationsTable ), |
|
73 | + 'length' => strlen( $translationString ) |
|
74 | 74 | ]; |
75 | - $translationsTable .= $translationString."\x00"; |
|
75 | + $translationsTable .= $translationString . "\x00"; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Offset of table with the original strings index: right after the header (which is 7 words) |
79 | 79 | $originalsIndexOffset = 7 * 4; |
80 | 80 | |
81 | 81 | // Size of table with the original strings index |
82 | - $originalsIndexSize = $numEntries * (4 + 4); |
|
82 | + $originalsIndexSize = $numEntries * ( 4 + 4 ); |
|
83 | 83 | |
84 | 84 | // Offset of table with the translation strings index: right after the original strings index table |
85 | 85 | $translationsIndexOffset = $originalsIndexOffset + $originalsIndexSize; |
86 | 86 | |
87 | 87 | // Size of table with the translation strings index |
88 | - $translationsIndexSize = $numEntries * (4 + 4); |
|
88 | + $translationsIndexSize = $numEntries * ( 4 + 4 ); |
|
89 | 89 | |
90 | 90 | // Hashing table starts after the header and after the index table |
91 | 91 | $originalsStringsOffset = $translationsIndexOffset + $translationsIndexSize; |
92 | 92 | |
93 | 93 | // Translations start after the keys |
94 | - $translationsStringsOffset = $originalsStringsOffset + strlen($originalsTable); |
|
94 | + $translationsStringsOffset = $originalsStringsOffset + strlen( $originalsTable ); |
|
95 | 95 | |
96 | 96 | // Let's generate the .mo file binary data |
97 | 97 | $mo = ''; |
98 | 98 | |
99 | 99 | // Magic number |
100 | - $mo .= pack('L', 0x950412de); |
|
100 | + $mo .= pack( 'L', 0x950412de ); |
|
101 | 101 | |
102 | 102 | // File format revision |
103 | - $mo .= pack('L', 0); |
|
103 | + $mo .= pack( 'L', 0 ); |
|
104 | 104 | |
105 | 105 | // Number of strings |
106 | - $mo .= pack('L', $numEntries); |
|
106 | + $mo .= pack( 'L', $numEntries ); |
|
107 | 107 | |
108 | 108 | // Offset of table with original strings |
109 | - $mo .= pack('L', $originalsIndexOffset); |
|
109 | + $mo .= pack( 'L', $originalsIndexOffset ); |
|
110 | 110 | |
111 | 111 | // Offset of table with translation strings |
112 | - $mo .= pack('L', $translationsIndexOffset); |
|
112 | + $mo .= pack( 'L', $translationsIndexOffset ); |
|
113 | 113 | |
114 | 114 | // Size of hashing table: we don't use it. |
115 | - $mo .= pack('L', 0); |
|
115 | + $mo .= pack( 'L', 0 ); |
|
116 | 116 | |
117 | 117 | // Offset of hashing table: it would start right after the translations index table |
118 | - $mo .= pack('L', $translationsIndexOffset + $translationsIndexSize); |
|
118 | + $mo .= pack( 'L', $translationsIndexOffset + $translationsIndexSize ); |
|
119 | 119 | |
120 | 120 | // Write the lengths & offsets of the original strings |
121 | - foreach ($originalsIndex as $info) { |
|
122 | - $mo .= pack('L', $info['length']); |
|
123 | - $mo .= pack('L', $originalsStringsOffset + $info['relativeOffset']); |
|
121 | + foreach ( $originalsIndex as $info ) { |
|
122 | + $mo .= pack( 'L', $info[ 'length' ] ); |
|
123 | + $mo .= pack( 'L', $originalsStringsOffset + $info[ 'relativeOffset' ] ); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | // Write the lengths & offsets of the translated strings |
127 | - foreach ($translationsIndex as $info) { |
|
128 | - $mo .= pack('L', $info['length']); |
|
129 | - $mo .= pack('L', $translationsStringsOffset + $info['relativeOffset']); |
|
127 | + foreach ( $translationsIndex as $info ) { |
|
128 | + $mo .= pack( 'L', $info[ 'length' ] ); |
|
129 | + $mo .= pack( 'L', $translationsStringsOffset + $info[ 'relativeOffset' ] ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | // Write original strings |
@@ -13,20 +13,20 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@parentDoc}. |
15 | 15 | */ |
16 | - public static function toString(Translations $translations, array $options = []) |
|
16 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
17 | 17 | { |
18 | 18 | $domain = $translations->getDomain() ?: 'messages'; |
19 | 19 | $options += static::$options; |
20 | 20 | |
21 | - return json_encode([ |
|
21 | + return json_encode( [ |
|
22 | 22 | $domain => [ |
23 | 23 | '' => [ |
24 | 24 | 'domain' => $domain, |
25 | 25 | 'lang' => $translations->getLanguage() ?: 'en', |
26 | - 'plural-forms' => $translations->getHeader('Plural-Forms') ?: 'nplurals=2; plural=(n != 1);', |
|
26 | + 'plural-forms' => $translations->getHeader( 'Plural-Forms' ) ?: 'nplurals=2; plural=(n != 1);', |
|
27 | 27 | ], |
28 | - ] + static::buildMessages($translations), |
|
29 | - ], $options['json']); |
|
28 | + ] + static::buildMessages( $translations ), |
|
29 | + ], $options[ 'json' ] ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -36,29 +36,29 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return array |
38 | 38 | */ |
39 | - protected static function buildMessages(Translations $translations) |
|
39 | + protected static function buildMessages( Translations $translations ) |
|
40 | 40 | { |
41 | 41 | $pluralForm = $translations->getPluralForms(); |
42 | - $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
|
43 | - $messages = []; |
|
42 | + $pluralSize = is_array( $pluralForm ) ? ( $pluralForm[ 0 ] - 1 ) : null; |
|
43 | + $messages = [ ]; |
|
44 | 44 | $context_glue = '\u0004'; |
45 | 45 | |
46 | - foreach ($translations as $translation) { |
|
47 | - if ($translation->isDisabled()) { |
|
46 | + foreach ( $translations as $translation ) { |
|
47 | + if ( $translation->isDisabled() ) { |
|
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
51 | - $key = ($translation->hasContext() ? $translation->getContext().$context_glue : '') |
|
51 | + $key = ( $translation->hasContext() ? $translation->getContext() . $context_glue : '' ) |
|
52 | 52 | .$translation->getOriginal(); |
53 | 53 | |
54 | - if ($translation->hasPluralTranslations(true)) { |
|
55 | - $message = $translation->getPluralTranslations($pluralSize); |
|
56 | - array_unshift($message, $translation->getTranslation()); |
|
54 | + if ( $translation->hasPluralTranslations( true ) ) { |
|
55 | + $message = $translation->getPluralTranslations( $pluralSize ); |
|
56 | + array_unshift( $message, $translation->getTranslation() ); |
|
57 | 57 | } else { |
58 | - $message = [$translation->getTranslation()]; |
|
58 | + $message = [ $translation->getTranslation() ]; |
|
59 | 59 | } |
60 | 60 | |
61 | - $messages[$key] = $message; |
|
61 | + $messages[ $key ] = $message; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return $messages; |
@@ -13,67 +13,67 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@parentDoc}. |
15 | 15 | */ |
16 | - public static function toString(Translations $translations, array $options = []) |
|
16 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
17 | 17 | { |
18 | 18 | $options += static::$options; |
19 | 19 | |
20 | 20 | $pluralForm = $translations->getPluralForms(); |
21 | - $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
|
22 | - $lines = ['msgid ""', 'msgstr ""']; |
|
21 | + $pluralSize = is_array( $pluralForm ) ? ( $pluralForm[ 0 ] - 1 ) : null; |
|
22 | + $lines = [ 'msgid ""', 'msgstr ""' ]; |
|
23 | 23 | |
24 | - foreach ($translations->getHeaders() as $name => $value) { |
|
25 | - $lines[] = sprintf('"%s: %s\\n"', $name, $value); |
|
24 | + foreach ( $translations->getHeaders() as $name => $value ) { |
|
25 | + $lines[ ] = sprintf( '"%s: %s\\n"', $name, $value ); |
|
26 | 26 | } |
27 | 27 | |
28 | - $lines[] = ''; |
|
28 | + $lines[ ] = ''; |
|
29 | 29 | |
30 | 30 | //Translations |
31 | - foreach ($translations as $translation) { |
|
32 | - if ($translation->hasComments()) { |
|
33 | - foreach ($translation->getComments() as $comment) { |
|
34 | - $lines[] = '# '.$comment; |
|
31 | + foreach ( $translations as $translation ) { |
|
32 | + if ( $translation->hasComments() ) { |
|
33 | + foreach ( $translation->getComments() as $comment ) { |
|
34 | + $lines[ ] = '# ' . $comment; |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | - if ($translation->hasExtractedComments()) { |
|
39 | - foreach ($translation->getExtractedComments() as $comment) { |
|
40 | - $lines[] = '#. '.$comment; |
|
38 | + if ( $translation->hasExtractedComments() ) { |
|
39 | + foreach ( $translation->getExtractedComments() as $comment ) { |
|
40 | + $lines[ ] = '#. ' . $comment; |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - if (!$options['noLocation'] && $translation->hasReferences()) { |
|
45 | - foreach ($translation->getReferences() as $reference) { |
|
46 | - $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null); |
|
44 | + if ( ! $options[ 'noLocation' ] && $translation->hasReferences() ) { |
|
45 | + foreach ( $translation->getReferences() as $reference ) { |
|
46 | + $lines[ ] = '#: ' . $reference[ 0 ] . ( ! is_null( $reference[ 1 ] ) ? ':' . $reference[ 1 ] : null ); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - if ($translation->hasFlags()) { |
|
51 | - $lines[] = '#, '.implode(',', $translation->getFlags()); |
|
50 | + if ( $translation->hasFlags() ) { |
|
51 | + $lines[ ] = '#, ' . implode( ',', $translation->getFlags() ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $prefix = $translation->isDisabled() ? '#~ ' : ''; |
55 | 55 | |
56 | - if ($translation->hasContext()) { |
|
57 | - $lines[] = $prefix.'msgctxt '.static::convertString($translation->getContext()); |
|
56 | + if ( $translation->hasContext() ) { |
|
57 | + $lines[ ] = $prefix . 'msgctxt ' . static::convertString( $translation->getContext() ); |
|
58 | 58 | } |
59 | 59 | |
60 | - static::addLines($lines, $prefix.'msgid', $translation->getOriginal()); |
|
60 | + static::addLines( $lines, $prefix . 'msgid', $translation->getOriginal() ); |
|
61 | 61 | |
62 | - if ($translation->hasPlural()) { |
|
63 | - static::addLines($lines, $prefix.'msgid_plural', $translation->getPlural()); |
|
64 | - static::addLines($lines, $prefix.'msgstr[0]', $translation->getTranslation()); |
|
62 | + if ( $translation->hasPlural() ) { |
|
63 | + static::addLines( $lines, $prefix . 'msgid_plural', $translation->getPlural() ); |
|
64 | + static::addLines( $lines, $prefix . 'msgstr[0]', $translation->getTranslation() ); |
|
65 | 65 | |
66 | - foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) { |
|
67 | - static::addLines($lines, $prefix.'msgstr['.($k + 1).']', $v); |
|
66 | + foreach ( $translation->getPluralTranslations( $pluralSize ) as $k => $v ) { |
|
67 | + static::addLines( $lines, $prefix . 'msgstr[' . ( $k + 1 ) . ']', $v ); |
|
68 | 68 | } |
69 | 69 | } else { |
70 | - static::addLines($lines, $prefix.'msgstr', $translation->getTranslation()); |
|
70 | + static::addLines( $lines, $prefix . 'msgstr', $translation->getTranslation() ); |
|
71 | 71 | } |
72 | 72 | |
73 | - $lines[] = ''; |
|
73 | + $lines[ ] = ''; |
|
74 | 74 | } |
75 | 75 | |
76 | - return implode("\n", $lines); |
|
76 | + return implode( "\n", $lines ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - protected static function multilineQuote($string) |
|
86 | + protected static function multilineQuote( $string ) |
|
87 | 87 | { |
88 | - $lines = explode("\n", $string); |
|
89 | - $last = count($lines) - 1; |
|
88 | + $lines = explode( "\n", $string ); |
|
89 | + $last = count( $lines ) - 1; |
|
90 | 90 | |
91 | - foreach ($lines as $k => $line) { |
|
92 | - if ($k === $last) { |
|
93 | - $lines[$k] = static::convertString($line); |
|
91 | + foreach ( $lines as $k => $line ) { |
|
92 | + if ( $k === $last ) { |
|
93 | + $lines[ $k ] = static::convertString( $line ); |
|
94 | 94 | } else { |
95 | - $lines[$k] = static::convertString($line."\n"); |
|
95 | + $lines[ $k ] = static::convertString( $line . "\n" ); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -106,17 +106,17 @@ discard block |
||
106 | 106 | * @param string $name |
107 | 107 | * @param string $value |
108 | 108 | */ |
109 | - protected static function addLines(array &$lines, $name, $value) |
|
109 | + protected static function addLines( array &$lines, $name, $value ) |
|
110 | 110 | { |
111 | - $newLines = static::multilineQuote($value); |
|
111 | + $newLines = static::multilineQuote( $value ); |
|
112 | 112 | |
113 | - if (count($newLines) === 1) { |
|
114 | - $lines[] = $name.' '.$newLines[0]; |
|
113 | + if ( count( $newLines ) === 1 ) { |
|
114 | + $lines[ ] = $name . ' ' . $newLines[ 0 ]; |
|
115 | 115 | } else { |
116 | - $lines[] = $name.' ""'; |
|
116 | + $lines[ ] = $name . ' ""'; |
|
117 | 117 | |
118 | - foreach ($newLines as $line) { |
|
119 | - $lines[] = $line; |
|
118 | + foreach ( $newLines as $line ) { |
|
119 | + $lines[ ] = $line; |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public static function convertString($value) |
|
131 | + public static function convertString( $value ) |
|
132 | 132 | { |
133 | - return '"'.strtr( |
|
133 | + return '"' . strtr( |
|
134 | 134 | $value, |
135 | 135 | [ |
136 | 136 | "\x00" => '', |
@@ -140,6 +140,6 @@ discard block |
||
140 | 140 | "\n" => '\n', |
141 | 141 | '"' => '\\"', |
142 | 142 | ] |
143 | - ).'"'; |
|
143 | + ) . '"'; |
|
144 | 144 | } |
145 | 145 | } |
@@ -17,10 +17,10 @@ |
||
17 | 17 | /** |
18 | 18 | * {@inheritdoc} |
19 | 19 | */ |
20 | - public static function toString(Translations $translations, array $options = []) |
|
20 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
21 | 21 | { |
22 | 22 | $options += static::$options; |
23 | 23 | |
24 | - return json_encode(static::toArray($translations, $options['includeHeaders'], true), $options['json']); |
|
24 | + return json_encode( static::toArray( $translations, $options[ 'includeHeaders' ], true ), $options[ 'json' ] ); |
|
25 | 25 | } |
26 | 26 | } |
@@ -9,11 +9,11 @@ |
||
9 | 9 | /** |
10 | 10 | * {@inheritdoc} |
11 | 11 | */ |
12 | - public static function toFile(Translations $translations, $file, array $options = []) |
|
12 | + public static function toFile( Translations $translations, $file, array $options = [ ] ) |
|
13 | 13 | { |
14 | - $content = static::toString($translations, $options); |
|
14 | + $content = static::toString( $translations, $options ); |
|
15 | 15 | |
16 | - if (file_put_contents($file, $content) === false) { |
|
16 | + if ( file_put_contents( $file, $content ) === false ) { |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * @see TranslatorInterface |
12 | 12 | */ |
13 | - public function noop($original) |
|
13 | + public function noop( $original ) |
|
14 | 14 | { |
15 | 15 | return $original; |
16 | 16 | } |
@@ -34,6 +34,6 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public static function includeFunctions() |
36 | 36 | { |
37 | - include_once __DIR__.'/translator_functions.php'; |
|
37 | + include_once __DIR__ . '/translator_functions.php'; |
|
38 | 38 | } |
39 | 39 | } |
@@ -9,20 +9,20 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @param string $language |
11 | 11 | */ |
12 | - public function __construct($language = null) |
|
12 | + public function __construct( $language = null ) |
|
13 | 13 | { |
14 | - if (!function_exists('gettext')) { |
|
15 | - throw new \RuntimeException('This class require the gettext extension for PHP'); |
|
14 | + if ( ! function_exists( 'gettext' ) ) { |
|
15 | + throw new \RuntimeException( 'This class require the gettext extension for PHP' ); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | //detects the language environment respecting the priority order |
19 | 19 | //http://php.net/manual/en/function.gettext.php#114062 |
20 | - if (empty($language)) { |
|
21 | - $language = getenv('LANGUAGE') ?: getenv('LC_ALL') ?: getenv('LC_MESSAGES') ?: getenv('LANG'); |
|
20 | + if ( empty( $language ) ) { |
|
21 | + $language = getenv( 'LANGUAGE' ) ?: getenv( 'LC_ALL' ) ?: getenv( 'LC_MESSAGES' ) ?: getenv( 'LANG' ); |
|
22 | 22 | } |
23 | 23 | |
24 | - if (!empty($language)) { |
|
25 | - $this->setLanguage($language); |
|
24 | + if ( ! empty( $language ) ) { |
|
25 | + $this->setLanguage( $language ); |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return self |
36 | 36 | */ |
37 | - public function setLanguage($language, $category = null) |
|
37 | + public function setLanguage( $language, $category = null ) |
|
38 | 38 | { |
39 | - if ($category === null) { |
|
40 | - $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL; |
|
39 | + if ( $category === null ) { |
|
40 | + $category = defined( 'LC_MESSAGES' ) ? LC_MESSAGES : LC_ALL; |
|
41 | 41 | } |
42 | 42 | |
43 | - setlocale($category, $language); |
|
44 | - putenv('LANGUAGE='.$language); |
|
43 | + setlocale( $category, $language ); |
|
44 | + putenv( 'LANGUAGE=' . $language ); |
|
45 | 45 | |
46 | 46 | return $this; |
47 | 47 | } |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return self |
57 | 57 | */ |
58 | - public function loadDomain($domain, $path = null, $default = true) |
|
58 | + public function loadDomain( $domain, $path = null, $default = true ) |
|
59 | 59 | { |
60 | - bindtextdomain($domain, $path); |
|
61 | - bind_textdomain_codeset($domain, 'UTF-8'); |
|
60 | + bindtextdomain( $domain, $path ); |
|
61 | + bind_textdomain_codeset( $domain, 'UTF-8' ); |
|
62 | 62 | |
63 | - if ($default) { |
|
64 | - textdomain($domain); |
|
63 | + if ( $default ) { |
|
64 | + textdomain( $domain ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | return $this; |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | * |
73 | 73 | * {@inheritdoc} |
74 | 74 | */ |
75 | - public function gettext($original) |
|
75 | + public function gettext( $original ) |
|
76 | 76 | { |
77 | - return gettext($original); |
|
77 | + return gettext( $original ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * |
83 | 83 | * {@inheritdoc} |
84 | 84 | */ |
85 | - public function ngettext($original, $plural, $value) |
|
85 | + public function ngettext( $original, $plural, $value ) |
|
86 | 86 | { |
87 | - return ngettext($original, $plural, $value); |
|
87 | + return ngettext( $original, $plural, $value ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * |
93 | 93 | * {@inheritdoc} |
94 | 94 | */ |
95 | - public function dngettext($domain, $original, $plural, $value) |
|
95 | + public function dngettext( $domain, $original, $plural, $value ) |
|
96 | 96 | { |
97 | - return dngettext($domain, $original, $plural, $value); |
|
97 | + return dngettext( $domain, $original, $plural, $value ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | * |
103 | 103 | * {@inheritdoc} |
104 | 104 | */ |
105 | - public function npgettext($context, $original, $plural, $value) |
|
105 | + public function npgettext( $context, $original, $plural, $value ) |
|
106 | 106 | { |
107 | - $message = $context."\x04".$original; |
|
108 | - $translation = ngettext($message, $plural, $value); |
|
107 | + $message = $context . "\x04" . $original; |
|
108 | + $translation = ngettext( $message, $plural, $value ); |
|
109 | 109 | |
110 | - return ($translation === $message) ? $original : $translation; |
|
110 | + return ( $translation === $message ) ? $original : $translation; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * |
116 | 116 | * {@inheritdoc} |
117 | 117 | */ |
118 | - public function pgettext($context, $original) |
|
118 | + public function pgettext( $context, $original ) |
|
119 | 119 | { |
120 | - $message = $context."\x04".$original; |
|
121 | - $translation = gettext($message); |
|
120 | + $message = $context . "\x04" . $original; |
|
121 | + $translation = gettext( $message ); |
|
122 | 122 | |
123 | - return ($translation === $message) ? $original : $translation; |
|
123 | + return ( $translation === $message ) ? $original : $translation; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * {@inheritdoc} |
130 | 130 | */ |
131 | - public function dgettext($domain, $original) |
|
131 | + public function dgettext( $domain, $original ) |
|
132 | 132 | { |
133 | - return dgettext($domain, $original); |
|
133 | + return dgettext( $domain, $original ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * |
139 | 139 | * {@inheritdoc} |
140 | 140 | */ |
141 | - public function dpgettext($domain, $context, $original) |
|
141 | + public function dpgettext( $domain, $context, $original ) |
|
142 | 142 | { |
143 | - $message = $context."\x04".$original; |
|
144 | - $translation = dgettext($domain, $message); |
|
143 | + $message = $context . "\x04" . $original; |
|
144 | + $translation = dgettext( $domain, $message ); |
|
145 | 145 | |
146 | - return ($translation === $message) ? $original : $translation; |
|
146 | + return ( $translation === $message ) ? $original : $translation; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | * |
152 | 152 | * {@inheritdoc} |
153 | 153 | */ |
154 | - public function dnpgettext($domain, $context, $original, $plural, $value) |
|
154 | + public function dnpgettext( $domain, $context, $original, $plural, $value ) |
|
155 | 155 | { |
156 | - $message = $context."\x04".$original; |
|
157 | - $translation = dngettext($domain, $message, $plural, $value); |
|
156 | + $message = $context . "\x04" . $original; |
|
157 | + $translation = dngettext( $domain, $message, $plural, $value ); |
|
158 | 158 | |
159 | - return ($translation === $message) ? $original : $translation; |
|
159 | + return ( $translation === $message ) ? $original : $translation; |
|
160 | 160 | } |
161 | 161 | } |