29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Localization 288<br />

.<br />

1 'welcome' => 'Welcome, :name',<br />

To replace the place-holders when retrieving a language line, pass an array of replacements as the<br />

second argument to the trans function:<br />

.<br />

1 echo trans('messages.welcome', ['name' => 'Dayle']);<br />

Pluralization<br />

Pluralization is a complex problem, as different languages have a variety of complex rules for<br />

pluralization. By using a “pipe” character, you may distinguish a singular and plural form of a<br />

string:<br />

.<br />

1 'apples' => 'There is one apple|There are many apples',<br />

Then, you may then use the trans_choice function to retrieve the line for a given “count”. In this<br />

example, since the count is greater than one, the plural form of the language line is returned:<br />

.<br />

1 echo trans_choice('messages.apples', 10);<br />

Since the Laravel translator is powered by the Symfony Translation component, you may create<br />

even more complex pluralization rules:<br />

.<br />

1 'apples' => '{0} There are none|[1,19] There are some|[20,Inf] There are many',<br />

Overriding Vendor Language Files<br />

Some packages may ship with their own language files. Instead of hacking the package’s core files<br />

to tweak these lines, you may override them by placing your own files in the resources/lang/vendor/{package}/{locale}<br />

directory.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!