1+ <?php
2+
3+ namespace App \Services ;
4+
5+ use Illuminate \Translation \Translator ;
6+
7+ /***************************************************************
8+ * This is just a very, very light modification to the default Laravel Translator.
9+ * The only difference it has is that it modifies the $locale
10+ * value when the pluralizations are done so we can switch over from en-US to en_US (for example).
11+ *
12+ * This means our translation directories can stay where they are (en-US), but the
13+ * pluralization code can get executed against a locale of en_US
14+ * (Which is required by Symfony, for some inexplicable reason)
15+ *
16+ * This method is called by the trans_choice() helper, which we *do* use a lot.
17+ ***************************************************************/
18+ class SnipeTranslator extends Translator {
19+
20+ //This is copied-and-pasted (almost) verbatim from Illuminate\Translation\Translator
21+ public function choice ($ key , $ number , array $ replace = [], $ locale = null )
22+ {
23+ $ line = $ this ->get (
24+ $ key , $ replace , $ locale = $ this ->localeForChoice ($ locale )
25+ );
26+
27+ // If the given "number" is actually an array or countable we will simply count the
28+ // number of elements in an instance. This allows developers to pass an array of
29+ // items without having to count it on their end first which gives bad syntax.
30+ if (is_array ($ number ) || $ number instanceof Countable) {
31+ $ number = count ($ number );
32+ }
33+
34+ $ replace ['count ' ] = $ number ;
35+
36+ $ underscored_locale = str_replace ("- " ,"_ " ,$ locale ); // OUR CHANGE.
37+ return $ this ->makeReplacements ( // BELOW - that $underscored_locale is the *ONLY* modified part
38+ $ this ->getSelector ()->choose ($ line , $ number , $ underscored_locale ), $ replace
39+ );
40+ }
41+
42+ }
0 commit comments