@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | * @param Translation $to |
| 40 | 40 | * @param int $options |
| 41 | 41 | */ |
| 42 | - public static function mergeFlags(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
| 42 | + public static function mergeFlags( Translation $from, Translation $to, $options = self::DEFAULTS ) |
|
| 43 | 43 | { |
| 44 | - if ($options & self::FLAGS_THEIRS) { |
|
| 44 | + if ( $options & self::FLAGS_THEIRS ) { |
|
| 45 | 45 | $to->deleteFlags(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if (!($options & self::FLAGS_OURS)) { |
|
| 49 | - foreach ($from->getFlags() as $flag) { |
|
| 50 | - $to->addFlag($flag); |
|
| 48 | + if ( ! ( $options & self::FLAGS_OURS ) ) { |
|
| 49 | + foreach ( $from->getFlags() as $flag ) { |
|
| 50 | + $to->addFlag( $flag ); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | * @param Translation $to |
| 60 | 60 | * @param int $options |
| 61 | 61 | */ |
| 62 | - public static function mergeExtractedComments(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
| 62 | + public static function mergeExtractedComments( Translation $from, Translation $to, $options = self::DEFAULTS ) |
|
| 63 | 63 | { |
| 64 | - if ($options & self::EXTRACTED_COMMENTS_THEIRS) { |
|
| 64 | + if ( $options & self::EXTRACTED_COMMENTS_THEIRS ) { |
|
| 65 | 65 | $to->deleteExtractedComments(); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if (!($options & self::EXTRACTED_COMMENTS_OURS)) { |
|
| 69 | - foreach ($from->getExtractedComments() as $comment) { |
|
| 70 | - $to->addExtractedComment($comment); |
|
| 68 | + if ( ! ( $options & self::EXTRACTED_COMMENTS_OURS ) ) { |
|
| 69 | + foreach ( $from->getExtractedComments() as $comment ) { |
|
| 70 | + $to->addExtractedComment( $comment ); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -79,15 +79,15 @@ discard block |
||
| 79 | 79 | * @param Translation $to |
| 80 | 80 | * @param int $options |
| 81 | 81 | */ |
| 82 | - public static function mergeComments(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
| 82 | + public static function mergeComments( Translation $from, Translation $to, $options = self::DEFAULTS ) |
|
| 83 | 83 | { |
| 84 | - if ($options & self::COMMENTS_THEIRS) { |
|
| 84 | + if ( $options & self::COMMENTS_THEIRS ) { |
|
| 85 | 85 | $to->deleteComments(); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if (!($options & self::COMMENTS_OURS)) { |
|
| 89 | - foreach ($from->getComments() as $comment) { |
|
| 90 | - $to->addComment($comment); |
|
| 88 | + if ( ! ( $options & self::COMMENTS_OURS ) ) { |
|
| 89 | + foreach ( $from->getComments() as $comment ) { |
|
| 90 | + $to->addComment( $comment ); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -99,15 +99,15 @@ discard block |
||
| 99 | 99 | * @param Translation $to |
| 100 | 100 | * @param int $options |
| 101 | 101 | */ |
| 102 | - public static function mergeReferences(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
| 102 | + public static function mergeReferences( Translation $from, Translation $to, $options = self::DEFAULTS ) |
|
| 103 | 103 | { |
| 104 | - if ($options & self::REFERENCES_THEIRS) { |
|
| 104 | + if ( $options & self::REFERENCES_THEIRS ) { |
|
| 105 | 105 | $to->deleteReferences(); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if (!($options & self::REFERENCES_OURS)) { |
|
| 109 | - foreach ($from->getReferences() as $reference) { |
|
| 110 | - $to->addReference($reference[0], $reference[1]); |
|
| 108 | + if ( ! ( $options & self::REFERENCES_OURS ) ) { |
|
| 109 | + foreach ( $from->getReferences() as $reference ) { |
|
| 110 | + $to->addReference( $reference[ 0 ], $reference[ 1 ] ); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -119,20 +119,20 @@ discard block |
||
| 119 | 119 | * @param Translation $to |
| 120 | 120 | * @param int $options |
| 121 | 121 | */ |
| 122 | - public static function mergeTranslation(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
| 122 | + public static function mergeTranslation( Translation $from, Translation $to, $options = self::DEFAULTS ) |
|
| 123 | 123 | { |
| 124 | - $override = (boolean) ($options & self::TRANSLATION_OVERRIDE); |
|
| 124 | + $override = (boolean)( $options & self::TRANSLATION_OVERRIDE ); |
|
| 125 | 125 | |
| 126 | - if (!$to->hasTranslation() || ($from->hasTranslation() && $override)) { |
|
| 127 | - $to->setTranslation($from->getTranslation()); |
|
| 126 | + if ( ! $to->hasTranslation() || ( $from->hasTranslation() && $override ) ) { |
|
| 127 | + $to->setTranslation( $from->getTranslation() ); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if (!$to->hasPlural() || ($from->hasPlural() && $override)) { |
|
| 131 | - $to->setPlural($from->getPlural()); |
|
| 130 | + if ( ! $to->hasPlural() || ( $from->hasPlural() && $override ) ) { |
|
| 131 | + $to->setPlural( $from->getPlural() ); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if (!$to->hasPluralTranslations() || ($from->hasPluralTranslations() && $override)) { |
|
| 135 | - $to->setPluralTranslations($from->getPluralTranslations()); |
|
| 134 | + if ( ! $to->hasPluralTranslations() || ( $from->hasPluralTranslations() && $override ) ) { |
|
| 135 | + $to->setPluralTranslations( $from->getPluralTranslations() ); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
@@ -143,25 +143,25 @@ discard block |
||
| 143 | 143 | * @param Translations $to |
| 144 | 144 | * @param int $options |
| 145 | 145 | */ |
| 146 | - public static function mergeTranslations(Translations $from, Translations $to, $options = self::DEFAULTS) |
|
| 146 | + public static function mergeTranslations( Translations $from, Translations $to, $options = self::DEFAULTS ) |
|
| 147 | 147 | { |
| 148 | - if ($options & self::REMOVE) { |
|
| 149 | - $filtered = []; |
|
| 148 | + if ( $options & self::REMOVE ) { |
|
| 149 | + $filtered = [ ]; |
|
| 150 | 150 | |
| 151 | - foreach ($to as $entry) { |
|
| 152 | - if ($from->find($entry)) { |
|
| 153 | - $filtered[$entry->getId()] = $entry; |
|
| 151 | + foreach ( $to as $entry ) { |
|
| 152 | + if ( $from->find( $entry ) ) { |
|
| 153 | + $filtered[ $entry->getId() ] = $entry; |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $to->exchangeArray($filtered); |
|
| 157 | + $to->exchangeArray( $filtered ); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - foreach ($from as $entry) { |
|
| 161 | - if (($existing = $to->find($entry))) { |
|
| 162 | - $existing->mergeWith($entry, $options); |
|
| 163 | - } elseif ($options & self::ADD) { |
|
| 164 | - $to[] = $entry->getClone(); |
|
| 160 | + foreach ( $from as $entry ) { |
|
| 161 | + if ( ( $existing = $to->find( $entry ) ) ) { |
|
| 162 | + $existing->mergeWith( $entry, $options ); |
|
| 163 | + } elseif ( $options & self::ADD ) { |
|
| 164 | + $to[ ] = $entry->getClone(); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -173,47 +173,47 @@ discard block |
||
| 173 | 173 | * @param Translations $to |
| 174 | 174 | * @param int $options |
| 175 | 175 | */ |
| 176 | - public static function mergeHeaders(Translations $from, Translations $to, $options = self::DEFAULTS) |
|
| 176 | + public static function mergeHeaders( Translations $from, Translations $to, $options = self::DEFAULTS ) |
|
| 177 | 177 | { |
| 178 | - if ($options & self::HEADERS_REMOVE) { |
|
| 179 | - foreach (array_keys($to->getHeaders()) as $name) { |
|
| 180 | - if ($from->getHeader($name) === null) { |
|
| 181 | - $to->deleteHeader($name); |
|
| 178 | + if ( $options & self::HEADERS_REMOVE ) { |
|
| 179 | + foreach ( array_keys( $to->getHeaders() ) as $name ) { |
|
| 180 | + if ( $from->getHeader( $name ) === null ) { |
|
| 181 | + $to->deleteHeader( $name ); |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - foreach ($from->getHeaders() as $name => $value) { |
|
| 187 | - $current = $to->getHeader($name); |
|
| 186 | + foreach ( $from->getHeaders() as $name => $value ) { |
|
| 187 | + $current = $to->getHeader( $name ); |
|
| 188 | 188 | |
| 189 | - if (empty($current)) { |
|
| 190 | - if ($options & self::HEADERS_ADD) { |
|
| 191 | - $to->setHeader($name, $value); |
|
| 189 | + if ( empty( $current ) ) { |
|
| 190 | + if ( $options & self::HEADERS_ADD ) { |
|
| 191 | + $to->setHeader( $name, $value ); |
|
| 192 | 192 | } |
| 193 | 193 | continue; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if (empty($value)) { |
|
| 196 | + if ( empty( $value ) ) { |
|
| 197 | 197 | continue; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - switch ($name) { |
|
| 200 | + switch ( $name ) { |
|
| 201 | 201 | case Translations::HEADER_LANGUAGE: |
| 202 | 202 | case Translations::HEADER_PLURAL: |
| 203 | - if ($options & self::LANGUAGE_OVERRIDE) { |
|
| 204 | - $to->setHeader($name, $value); |
|
| 203 | + if ( $options & self::LANGUAGE_OVERRIDE ) { |
|
| 204 | + $to->setHeader( $name, $value ); |
|
| 205 | 205 | } |
| 206 | 206 | break; |
| 207 | 207 | |
| 208 | 208 | case Translations::HEADER_DOMAIN: |
| 209 | - if ($options & self::DOMAIN_OVERRIDE) { |
|
| 210 | - $to->setHeader($name, $value); |
|
| 209 | + if ( $options & self::DOMAIN_OVERRIDE ) { |
|
| 210 | + $to->setHeader( $name, $value ); |
|
| 211 | 211 | } |
| 212 | 212 | break; |
| 213 | 213 | |
| 214 | 214 | default: |
| 215 | - if ($options & self::HEADERS_OVERRIDE) { |
|
| 216 | - $to->setHeader($name, $value); |
|
| 215 | + if ( $options & self::HEADERS_OVERRIDE ) { |
|
| 216 | + $to->setHeader( $name, $value ); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | } |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -spl_autoload_register(function ($class) { |
|
| 4 | - if (strpos($class, 'Gettext\\') !== 0) { |
|
| 3 | +spl_autoload_register( function( $class ) { |
|
| 4 | + if ( strpos( $class, 'Gettext\\' ) !== 0 ) { |
|
| 5 | 5 | return; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | - $file = __DIR__.str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen('Gettext'))).'.php'; |
|
| 8 | + $file = __DIR__ . str_replace( '\\', DIRECTORY_SEPARATOR, substr( $class, strlen( 'Gettext' ) ) ) . '.php'; |
|
| 9 | 9 | |
| 10 | - if (is_file($file)) { |
|
| 10 | + if ( is_file( $file ) ) { |
|
| 11 | 11 | require_once $file; |
| 12 | 12 | } |
| 13 | 13 | }); |
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | class Translator extends BaseTranslator implements TranslatorInterface |
| 8 | 8 | { |
| 9 | 9 | protected $domain; |
| 10 | - protected $dictionary = []; |
|
| 11 | - protected $plurals = []; |
|
| 10 | + protected $dictionary = [ ]; |
|
| 11 | + protected $plurals = [ ]; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Loads translation from a Translations instance, a file on an array. |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @return static |
| 19 | 19 | */ |
| 20 | - public function loadTranslations($translations) |
|
| 20 | + public function loadTranslations( $translations ) |
|
| 21 | 21 | { |
| 22 | - if (is_object($translations) && $translations instanceof Translations) { |
|
| 23 | - $translations = PhpArray::generate($translations, ['includeHeaders' => false]); |
|
| 24 | - } elseif (is_string($translations) && is_file($translations)) { |
|
| 22 | + if ( is_object( $translations ) && $translations instanceof Translations ) { |
|
| 23 | + $translations = PhpArray::generate( $translations, [ 'includeHeaders' => false ] ); |
|
| 24 | + } elseif ( is_string( $translations ) && is_file( $translations ) ) { |
|
| 25 | 25 | $translations = include $translations; |
| 26 | - } elseif (!is_array($translations)) { |
|
| 26 | + } elseif ( ! is_array( $translations ) ) { |
|
| 27 | 27 | throw new \InvalidArgumentException( |
| 28 | 28 | 'Invalid Translator: only arrays, files or instance of Translations are allowed' |
| 29 | 29 | ); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $this->addTranslations($translations); |
|
| 32 | + $this->addTranslations( $translations ); |
|
| 33 | 33 | |
| 34 | 34 | return $this; |
| 35 | 35 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @return static |
| 43 | 43 | */ |
| 44 | - public function defaultDomain($domain) |
|
| 44 | + public function defaultDomain( $domain ) |
|
| 45 | 45 | { |
| 46 | 46 | $this->domain = $domain; |
| 47 | 47 | |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * {@inheritdoc} |
| 55 | 55 | */ |
| 56 | - public function gettext($original) |
|
| 56 | + public function gettext( $original ) |
|
| 57 | 57 | { |
| 58 | - return $this->dpgettext($this->domain, null, $original); |
|
| 58 | + return $this->dpgettext( $this->domain, null, $original ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * {@inheritdoc} |
| 65 | 65 | */ |
| 66 | - public function ngettext($original, $plural, $value) |
|
| 66 | + public function ngettext( $original, $plural, $value ) |
|
| 67 | 67 | { |
| 68 | - return $this->dnpgettext($this->domain, null, $original, $plural, $value); |
|
| 68 | + return $this->dnpgettext( $this->domain, null, $original, $plural, $value ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * {@inheritdoc} |
| 75 | 75 | */ |
| 76 | - public function dngettext($domain, $original, $plural, $value) |
|
| 76 | + public function dngettext( $domain, $original, $plural, $value ) |
|
| 77 | 77 | { |
| 78 | - return $this->dnpgettext($domain, null, $original, $plural, $value); |
|
| 78 | + return $this->dnpgettext( $domain, null, $original, $plural, $value ); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * {@inheritdoc} |
| 85 | 85 | */ |
| 86 | - public function npgettext($context, $original, $plural, $value) |
|
| 86 | + public function npgettext( $context, $original, $plural, $value ) |
|
| 87 | 87 | { |
| 88 | - return $this->dnpgettext($this->domain, $context, $original, $plural, $value); |
|
| 88 | + return $this->dnpgettext( $this->domain, $context, $original, $plural, $value ); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * {@inheritdoc} |
| 95 | 95 | */ |
| 96 | - public function pgettext($context, $original) |
|
| 96 | + public function pgettext( $context, $original ) |
|
| 97 | 97 | { |
| 98 | - return $this->dpgettext($this->domain, $context, $original); |
|
| 98 | + return $this->dpgettext( $this->domain, $context, $original ); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * {@inheritdoc} |
| 105 | 105 | */ |
| 106 | - public function dgettext($domain, $original) |
|
| 106 | + public function dgettext( $domain, $original ) |
|
| 107 | 107 | { |
| 108 | - return $this->dpgettext($domain, null, $original); |
|
| 108 | + return $this->dpgettext( $domain, null, $original ); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * {@inheritdoc} |
| 115 | 115 | */ |
| 116 | - public function dpgettext($domain, $context, $original) |
|
| 116 | + public function dpgettext( $domain, $context, $original ) |
|
| 117 | 117 | { |
| 118 | - $translation = $this->getTranslation($domain, $context, $original); |
|
| 118 | + $translation = $this->getTranslation( $domain, $context, $original ); |
|
| 119 | 119 | |
| 120 | - if (isset($translation[0]) && $translation[0] !== '') { |
|
| 121 | - return $translation[0]; |
|
| 120 | + if ( isset( $translation[ 0 ] ) && $translation[ 0 ] !== '' ) { |
|
| 121 | + return $translation[ 0 ]; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | return $original; |
@@ -129,16 +129,16 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * {@inheritdoc} |
| 131 | 131 | */ |
| 132 | - public function dnpgettext($domain, $context, $original, $plural, $value) |
|
| 132 | + public function dnpgettext( $domain, $context, $original, $plural, $value ) |
|
| 133 | 133 | { |
| 134 | - $translation = $this->getTranslation($domain, $context, $original); |
|
| 135 | - $key = $this->getPluralIndex($domain, $value, $translation === false); |
|
| 134 | + $translation = $this->getTranslation( $domain, $context, $original ); |
|
| 135 | + $key = $this->getPluralIndex( $domain, $value, $translation === false ); |
|
| 136 | 136 | |
| 137 | - if (isset($translation[$key]) && $translation[$key] !== '') { |
|
| 138 | - return $translation[$key]; |
|
| 137 | + if ( isset( $translation[ $key ] ) && $translation[ $key ] !== '' ) { |
|
| 138 | + return $translation[ $key ]; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - return ($key === 0) ? $original : $plural; |
|
| 141 | + return ( $key === 0 ) ? $original : $plural; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -146,33 +146,33 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @param array $translations |
| 148 | 148 | */ |
| 149 | - protected function addTranslations(array $translations) |
|
| 149 | + protected function addTranslations( array $translations ) |
|
| 150 | 150 | { |
| 151 | - $domain = isset($translations['domain']) ? $translations['domain'] : ''; |
|
| 151 | + $domain = isset( $translations[ 'domain' ] ) ? $translations[ 'domain' ] : ''; |
|
| 152 | 152 | |
| 153 | 153 | //Set the first domain loaded as default domain |
| 154 | - if ($this->domain === null) { |
|
| 154 | + if ( $this->domain === null ) { |
|
| 155 | 155 | $this->domain = $domain; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if (isset($this->dictionary[$domain])) { |
|
| 159 | - $this->dictionary[$domain] = array_replace_recursive($this->dictionary[$domain], $translations['messages']); |
|
| 158 | + if ( isset( $this->dictionary[ $domain ] ) ) { |
|
| 159 | + $this->dictionary[ $domain ] = array_replace_recursive( $this->dictionary[ $domain ], $translations[ 'messages' ] ); |
|
| 160 | 160 | |
| 161 | 161 | return; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if (!empty($translations['plural-forms'])) { |
|
| 165 | - list($count, $code) = array_map('trim', explode(';', $translations['plural-forms'], 2)); |
|
| 164 | + if ( ! empty( $translations[ 'plural-forms' ] ) ) { |
|
| 165 | + list( $count, $code ) = array_map( 'trim', explode( ';', $translations[ 'plural-forms' ], 2 ) ); |
|
| 166 | 166 | |
| 167 | 167 | // extract just the expression turn 'n' into a php variable '$n'. |
| 168 | 168 | // Slap on a return keyword and semicolon at the end. |
| 169 | - $this->plurals[$domain] = [ |
|
| 170 | - 'count' => (int) str_replace('nplurals=', '', $count), |
|
| 171 | - 'code' => str_replace('plural=', 'return ', str_replace('n', '$n', $code)).';', |
|
| 169 | + $this->plurals[ $domain ] = [ |
|
| 170 | + 'count' => (int)str_replace( 'nplurals=', '', $count ), |
|
| 171 | + 'code' => str_replace( 'plural=', 'return ', str_replace( 'n', '$n', $code ) ) . ';', |
|
| 172 | 172 | ]; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - $this->dictionary[$domain] = $translations['messages']; |
|
| 175 | + $this->dictionary[ $domain ] = $translations[ 'messages' ]; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return string|false |
| 186 | 186 | */ |
| 187 | - protected function getTranslation($domain, $context, $original) |
|
| 187 | + protected function getTranslation( $domain, $context, $original ) |
|
| 188 | 188 | { |
| 189 | - return isset($this->dictionary[$domain][$context][$original]) |
|
| 190 | - ? $this->dictionary[$domain][$context][$original] |
|
| 189 | + return isset( $this->dictionary[ $domain ][ $context ][ $original ] ) |
|
| 190 | + ? $this->dictionary[ $domain ][ $context ][ $original ] |
|
| 191 | 191 | : false; |
| 192 | 192 | } |
| 193 | 193 | |
@@ -201,23 +201,23 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @return int |
| 203 | 203 | */ |
| 204 | - protected function getPluralIndex($domain, $n, $fallback) |
|
| 204 | + protected function getPluralIndex( $domain, $n, $fallback ) |
|
| 205 | 205 | { |
| 206 | 206 | //Not loaded domain or translation, use a fallback |
| 207 | - if (!isset($this->plurals[$domain]) || $fallback === true) { |
|
| 207 | + if ( ! isset( $this->plurals[ $domain ] ) || $fallback === true ) { |
|
| 208 | 208 | return $n == 1 ? 0 : 1; |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if (!isset($this->plurals[$domain]['function'])) { |
|
| 212 | - $code = static::fixTerseIfs($this->plurals[$domain]['code']); |
|
| 213 | - $this->plurals[$domain]['function'] = eval("return function (\$n) { $code };"); |
|
| 211 | + if ( ! isset( $this->plurals[ $domain ][ 'function' ] ) ) { |
|
| 212 | + $code = static::fixTerseIfs( $this->plurals[ $domain ][ 'code' ] ); |
|
| 213 | + $this->plurals[ $domain ][ 'function' ] = eval( "return function (\$n) { $code };" ); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if ($this->plurals[$domain]['count'] <= 2) { |
|
| 217 | - return call_user_func($this->plurals[$domain]['function'], $n) ? 1 : 0; |
|
| 216 | + if ( $this->plurals[ $domain ][ 'count' ] <= 2 ) { |
|
| 217 | + return call_user_func( $this->plurals[ $domain ][ 'function' ], $n ) ? 1 : 0; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - return call_user_func($this->plurals[$domain]['function'], $n); |
|
| 220 | + return call_user_func( $this->plurals[ $domain ][ 'function' ], $n ); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return string A formatted terse If that PHP can work with. |
| 238 | 238 | */ |
| 239 | - private static function fixTerseIfs($code, $inner = false) |
|
| 239 | + private static function fixTerseIfs( $code, $inner = false ) |
|
| 240 | 240 | { |
| 241 | 241 | /* |
| 242 | 242 | * (?P<expression>[^?]+) Capture everything up to ? as 'expression' |
@@ -245,22 +245,22 @@ discard block |
||
| 245 | 245 | * : : |
| 246 | 246 | * (?P<failure>[^;]+) Capture everything up to ; as 'failure' |
| 247 | 247 | */ |
| 248 | - preg_match('/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/', $code, $matches); |
|
| 248 | + preg_match( '/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/', $code, $matches ); |
|
| 249 | 249 | |
| 250 | 250 | // If no match was found then no terse if was present |
| 251 | - if (!isset($matches[0])) { |
|
| 251 | + if ( ! isset( $matches[ 0 ] ) ) { |
|
| 252 | 252 | return $code; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $expression = $matches['expression']; |
|
| 256 | - $success = $matches['success']; |
|
| 257 | - $failure = $matches['failure']; |
|
| 255 | + $expression = $matches[ 'expression' ]; |
|
| 256 | + $success = $matches[ 'success' ]; |
|
| 257 | + $failure = $matches[ 'failure' ]; |
|
| 258 | 258 | |
| 259 | 259 | // Go look for another terse if in the failure state. |
| 260 | - $failure = static::fixTerseIfs($failure, true); |
|
| 261 | - $code = $expression.' ? '.$success.' : '.$failure; |
|
| 260 | + $failure = static::fixTerseIfs( $failure, true ); |
|
| 261 | + $code = $expression . ' ? ' . $success . ' : ' . $failure; |
|
| 262 | 262 | |
| 263 | - if ($inner) { |
|
| 263 | + if ( $inner ) { |
|
| 264 | 264 | return "($code)"; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -16,18 +16,18 @@ |
||
| 16 | 16 | /** |
| 17 | 17 | * {@inheritdoc} |
| 18 | 18 | */ |
| 19 | - public static function fromFile($file, Translations $translations, array $options = []) |
|
| 19 | + public static function fromFile( $file, Translations $translations, array $options = [ ] ) |
|
| 20 | 20 | { |
| 21 | - foreach (static::getFiles($file) as $file) { |
|
| 22 | - static::fromArray(include($file), $translations); |
|
| 21 | + foreach ( static::getFiles( $file ) as $file ) { |
|
| 22 | + static::fromArray( include( $file ), $translations ); |
|
| 23 | 23 | } |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * {@inheritdoc} |
| 28 | 28 | */ |
| 29 | - public static function fromString($string, Translations $translations, array $options = []) |
|
| 29 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
| 30 | 30 | { |
| 31 | - throw new BadMethodCallException('PhpArray::fromString() cannot be called. Use PhpArray::fromFile()'); |
|
| 31 | + throw new BadMethodCallException( 'PhpArray::fromString() cannot be called. Use PhpArray::fromFile()' ); |
|
| 32 | 32 | } |
| 33 | 33 | } |
@@ -23,25 +23,25 @@ |
||
| 23 | 23 | /** |
| 24 | 24 | * {@inheritdoc} |
| 25 | 25 | */ |
| 26 | - public static function fromString($string, Translations $translations, array $options = []) |
|
| 26 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
| 27 | 27 | { |
| 28 | 28 | $options += static::$options; |
| 29 | - $handle = fopen('php://memory', 'w'); |
|
| 29 | + $handle = fopen( 'php://memory', 'w' ); |
|
| 30 | 30 | |
| 31 | - fputs($handle, $string); |
|
| 32 | - rewind($handle); |
|
| 31 | + fputs( $handle, $string ); |
|
| 32 | + rewind( $handle ); |
|
| 33 | 33 | |
| 34 | - while ($row = static::fgetcsv($handle, $options)) { |
|
| 35 | - list($original, $translation) = $row + ['', '']; |
|
| 34 | + while ( $row = static::fgetcsv( $handle, $options ) ) { |
|
| 35 | + list( $original, $translation ) = $row + [ '', '' ]; |
|
| 36 | 36 | |
| 37 | - if ($original === '') { |
|
| 38 | - static::extractHeaders($translation, $translations); |
|
| 37 | + if ( $original === '' ) { |
|
| 38 | + static::extractHeaders( $translation, $translations ); |
|
| 39 | 39 | continue; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $translations->insert(null, $original)->setTranslation($translation); |
|
| 42 | + $translations->insert( null, $original )->setTranslation( $translation ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - fclose($handle); |
|
| 45 | + fclose( $handle ); |
|
| 46 | 46 | } |
| 47 | 47 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | class JsCode extends Extractor implements ExtractorInterface, ExtractorMultiInterface |
| 13 | 13 | { |
| 14 | 14 | public static $options = [ |
| 15 | - 'constants' => [], |
|
| 15 | + 'constants' => [ ], |
|
| 16 | 16 | |
| 17 | 17 | 'functions' => [ |
| 18 | 18 | 'gettext' => 'gettext', |
@@ -42,33 +42,33 @@ discard block |
||
| 42 | 42 | * @inheritdoc |
| 43 | 43 | * @throws Exception |
| 44 | 44 | */ |
| 45 | - public static function fromString($string, Translations $translations, array $options = []) |
|
| 45 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
| 46 | 46 | { |
| 47 | - static::fromStringMultiple($string, [$translations], $options); |
|
| 47 | + static::fromStringMultiple( $string, [ $translations ], $options ); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * @inheritDoc |
| 52 | 52 | * @throws Exception |
| 53 | 53 | */ |
| 54 | - public static function fromStringMultiple($string, array $translations, array $options = []) |
|
| 54 | + public static function fromStringMultiple( $string, array $translations, array $options = [ ] ) |
|
| 55 | 55 | { |
| 56 | 56 | $options += static::$options; |
| 57 | 57 | |
| 58 | 58 | /** @var FunctionsScanner $functions */ |
| 59 | - $functions = new static::$functionsScannerClass($string); |
|
| 60 | - $functions->saveGettextFunctions($translations, $options); |
|
| 59 | + $functions = new static::$functionsScannerClass( $string ); |
|
| 60 | + $functions->saveGettextFunctions( $translations, $options ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @inheritDoc |
| 65 | 65 | * @throws Exception |
| 66 | 66 | */ |
| 67 | - public static function fromFileMultiple($file, array $translations, array $options = []) |
|
| 67 | + public static function fromFileMultiple( $file, array $translations, array $options = [ ] ) |
|
| 68 | 68 | { |
| 69 | - foreach (static::getFiles($file) as $file) { |
|
| 70 | - $options['file'] = $file; |
|
| 71 | - static::fromStringMultiple(static::readFile($file), $translations, $options); |
|
| 69 | + foreach ( static::getFiles( $file ) as $file ) { |
|
| 70 | + $options[ 'file' ] = $file; |
|
| 71 | + static::fromStringMultiple( static::readFile( $file ), $translations, $options ); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -19,66 +19,66 @@ |
||
| 19 | 19 | /** |
| 20 | 20 | * {@inheritdoc} |
| 21 | 21 | */ |
| 22 | - public static function fromString($string, Translations $translations, array $options = []) |
|
| 22 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
| 23 | 23 | { |
| 24 | 24 | $options += static::$options; |
| 25 | 25 | |
| 26 | - $xml = new SimpleXMLElement($string, null, false); |
|
| 26 | + $xml = new SimpleXMLElement( $string, null, false ); |
|
| 27 | 27 | |
| 28 | - foreach ($xml->file as $file) { |
|
| 29 | - if (isset($file->notes)) { |
|
| 30 | - foreach ($file->notes->note as $note) { |
|
| 31 | - $translations->setHeader($note['id'], (string) $note); |
|
| 28 | + foreach ( $xml->file as $file ) { |
|
| 29 | + if ( isset( $file->notes ) ) { |
|
| 30 | + foreach ( $file->notes->note as $note ) { |
|
| 31 | + $translations->setHeader( $note[ 'id' ], (string)$note ); |
|
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - foreach ($file->unit as $unit) { |
|
| 36 | - foreach ($unit->segment as $segment) { |
|
| 37 | - $targets = []; |
|
| 35 | + foreach ( $file->unit as $unit ) { |
|
| 36 | + foreach ( $unit->segment as $segment ) { |
|
| 37 | + $targets = [ ]; |
|
| 38 | 38 | |
| 39 | - foreach ($segment->target as $target) { |
|
| 40 | - $targets[] = (string) $target; |
|
| 39 | + foreach ( $segment->target as $target ) { |
|
| 40 | + $targets[ ] = (string)$target; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - $translation = $translations->createNewTranslation(null, (string) $segment->source); |
|
| 44 | - if (isset($unit['id'])) { |
|
| 45 | - $unitId = (string) $unit['id']; |
|
| 46 | - $translation->addComment("XLIFF_UNIT_ID: $unitId"); |
|
| 47 | - if ($options['unitid_as_id']) { |
|
| 48 | - $translation->setId($unitId); |
|
| 43 | + $translation = $translations->createNewTranslation( null, (string)$segment->source ); |
|
| 44 | + if ( isset( $unit[ 'id' ] ) ) { |
|
| 45 | + $unitId = (string)$unit[ 'id' ]; |
|
| 46 | + $translation->addComment( "XLIFF_UNIT_ID: $unitId" ); |
|
| 47 | + if ( $options[ 'unitid_as_id' ] ) { |
|
| 48 | + $translation->setId( $unitId ); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | - $translation->setTranslation(array_shift($targets)); |
|
| 52 | - $translation->setPluralTranslations($targets); |
|
| 51 | + $translation->setTranslation( array_shift( $targets ) ); |
|
| 52 | + $translation->setPluralTranslations( $targets ); |
|
| 53 | 53 | |
| 54 | - if (isset($unit->notes)) { |
|
| 55 | - foreach ($unit->notes->note as $note) { |
|
| 56 | - switch ($note['category']) { |
|
| 54 | + if ( isset( $unit->notes ) ) { |
|
| 55 | + foreach ( $unit->notes->note as $note ) { |
|
| 56 | + switch ( $note[ 'category' ] ) { |
|
| 57 | 57 | case 'context': |
| 58 | - $translation = $translation->getClone((string) $note); |
|
| 58 | + $translation = $translation->getClone( (string)$note ); |
|
| 59 | 59 | break; |
| 60 | 60 | |
| 61 | 61 | case 'extracted-comment': |
| 62 | - $translation->addExtractedComment((string) $note); |
|
| 62 | + $translation->addExtractedComment( (string)$note ); |
|
| 63 | 63 | break; |
| 64 | 64 | |
| 65 | 65 | case 'flag': |
| 66 | - $translation->addFlag((string) $note); |
|
| 66 | + $translation->addFlag( (string)$note ); |
|
| 67 | 67 | break; |
| 68 | 68 | |
| 69 | 69 | case 'reference': |
| 70 | - $ref = explode(':', (string) $note, 2); |
|
| 71 | - $translation->addReference($ref[0], isset($ref[1]) ? $ref[1] : null); |
|
| 70 | + $ref = explode( ':', (string)$note, 2 ); |
|
| 71 | + $translation->addReference( $ref[ 0 ], isset( $ref[ 1 ] ) ? $ref[ 1 ] : null ); |
|
| 72 | 72 | break; |
| 73 | 73 | |
| 74 | 74 | default: |
| 75 | - $translation->addComment((string) $note); |
|
| 75 | + $translation->addComment( (string)$note ); |
|
| 76 | 76 | break; |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $translations[] = $translation; |
|
| 81 | + $translations[ ] = $translation; |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -16,12 +16,12 @@ |
||
| 16 | 16 | /** |
| 17 | 17 | * {@inheritdoc} |
| 18 | 18 | */ |
| 19 | - public static function fromString($string, Translations $translations, array $options = []) |
|
| 19 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
| 20 | 20 | { |
| 21 | - $messages = YamlParser::parse($string); |
|
| 21 | + $messages = YamlParser::parse( $string ); |
|
| 22 | 22 | |
| 23 | - if (is_array($messages)) { |
|
| 24 | - static::fromArray($messages, $translations); |
|
| 23 | + if ( is_array( $messages ) ) { |
|
| 24 | + static::fromArray( $messages, $translations ); |
|
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * {@inheritdoc} |
| 23 | 23 | */ |
| 24 | - public static function fromString($string, Translations $translations, array $options = []) |
|
| 24 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
| 25 | 25 | { |
| 26 | 26 | $options += static::$options; |
| 27 | 27 | |
| 28 | - $twig = $options['twig'] ?: static::createTwig(); |
|
| 28 | + $twig = $options[ 'twig' ] ?: static::createTwig(); |
|
| 29 | 29 | |
| 30 | - PhpCode::fromString($twig->compileSource(new Twig_Source($string, '')), $translations, $options); |
|
| 30 | + PhpCode::fromString( $twig->compileSource( new Twig_Source( $string, '' ) ), $translations, $options ); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | protected static function createTwig() |
| 39 | 39 | { |
| 40 | - $twig = new Twig_Environment(new Twig_Loader_Array(['' => ''])); |
|
| 41 | - $twig->addExtension(new Twig_Extensions_Extension_I18n()); |
|
| 40 | + $twig = new Twig_Environment( new Twig_Loader_Array( [ '' => '' ] ) ); |
|
| 41 | + $twig->addExtension( new Twig_Extensions_Extension_I18n() ); |
|
| 42 | 42 | |
| 43 | - return static::$options['twig'] = $twig; |
|
| 43 | + return static::$options[ 'twig' ] = $twig; |
|
| 44 | 44 | } |
| 45 | 45 | } |