Build a Gettext Wrapper

These days I’m working on two projects based on laravel and I have to implement the localization. So I found out that the most used method is using Gettext.
I have some difficulties translating strings with only gettext() and ngettext(). I’d build a wrapper able to translate strings like so:

fantasticFunction('Hi my name is :name and I have {n, one friend, :n friends}', [ 'name' => 'Luca', 'n' => 1 ])

Instead of writing:

sprintf('Hi my name is %s and I have', name) . ' ' . $n . ngettext('friend', 'friends', $n)

so the problem is: if I’d make such as wrapper, then tools like poedit would not recognize that strings. How can I solve?

Source: laravel

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.