Closed loranger closed 10 years ago
Hi Loranger,
could you try executing the following command first:
$ php artisan l4gettext:fetch
That should publish the config files and try to auto detect the installed locales and set them correctly in the config files.
Hi netson, Thanks for your fast reply.
I have the exact same error :
% php artisan l4gettext:fetch
{"error":{"type":"Netson\\L4gettext\\LocaleNotFoundException","message":"The given locale [en_US.utf8] could not be set; it seems it does not exist on this system","file":"\/Users\/loranger\/Sites\/projects\/dbg\/vendor\/netson\/l4gettext\/src\/Netson\/L4gettext\/L4gettext.php","line":109}}
I also verified all my locales and en_US exists, but with the dash (UTF-8) :
% locale -a
af_ZA
(...)
en_AU
en_AU.ISO8859-1
en_AU.ISO8859-15
en_AU.US-ASCII
en_AU.UTF-8
en_CA
en_CA.ISO8859-1
en_CA.ISO8859-15
en_CA.US-ASCII
en_CA.UTF-8
en_GB
en_GB.ISO8859-1
en_GB.ISO8859-15
en_GB.US-ASCII
en_GB.UTF-8
en_IE
en_IE.UTF-8
en_NZ
en_NZ.ISO8859-1
en_NZ.ISO8859-15
en_NZ.US-ASCII
en_NZ.UTF-8
en_US
en_US.ISO8859-1
en_US.ISO8859-15
en_US.US-ASCII
en_US.UTF-8
(...)
fr_FR
fr_FR.ISO8859-1
fr_FR.ISO8859-15
fr_FR.UTF-8
(...)
zh_TW.UTF-8
C
POSIX
Could you manually update the (published) config/encoding.php file to include the UTF-8 encoding? That may do the trick
After that you may be able to use the fetch command to auto-populate the files. Also, make sure you set your desired default locale/encoding in the (published) config.php file
I'd love to, but I'm afraid I haven't any published files in config folder. I found encodings.dist and locales.dist in /vendor/netson/l4gettext/src/config/ as their full versions, but I'm not sure what I am supposed to leave and what I am supposed to kepp. Could you provide me instructions, please ?
I think you may have uncovered a slight design flaw in the setup/install process; I'll have to look into that. For now I suggest you manually "publish" the files by copying the files from the folder
/vendor/netson/l4gettext/src/config
to the folder:
/app/config/packages/netson/l4gettext
If this folder does not exist, create it manually.
Then, add the UTF-8 locale to the list and you can leave all others in tact, or remove them and then after making the changes, attempt to use the fetch command once again.
Let me know if that works!
I did create the netson/l4gettext
in my /app/config/packages/
folder, then copy-paste all the files from /vendor/netson/l4gettext/src/config
then add "UTF-8" and "utf-8" to the encodings.php file, before "utf8" and tried to fetch again, but I'm sorry to say it did not work :
% ./artisan l4gettext:fetch ⏎
{"error":{"type":"Netson\\L4gettext\\LocaleNotFoundException","message":"The given locale [en_US.utf8] could not be set; it seems it does not exist on this system","file":"\/Users\/loranger\/Sites\/projects\/myproject\/vendor\/netson\/l4gettext\/src\/Netson\/L4gettext\/L4gettext.php","line":109}}
Sorry, I forgot to mention that you should also update the config file /app/config/packages/netson/l4gettext/config.php
. Make sure you set the default encoding to UTF-8:
'default_encoding' => 'UTF-8',
Perfect, everything seems working. I hope you'll find where the issue comes from in order to allow other gettext fans to use l4gettext.
Thank you for your support.
You're welcome! :) I know where to look to fix the installation issue, it has to do with the fact that the ServiceProvider attempts to load the module using the default settings, but if the default setting requires a locale that doesn't exist, you cannot publish the config files to change the default settings, so it creates a chicken and egg problem... let's see if I can find the egg before the chicken does! :P
Hey Loranger, I just made a small change which should fix the issue you were seeing earlier today. If you would be so kind as to test it, that would be greatly appreciated!
Hello netson,
Wow, that was a fast fix !
So I did it again, from scratch :
./artisan l4gettext:fetch
and it worked ! :ok_hand: The config files are published, but they still breaks laravel : Just after, if I call artisan again (without) any argument I got the following error :
% ./artisan
{"error":{"type":"Netson\\L4gettext\\InvalidEncodingException","message":"The provided encoding [utf8] does not exist in the list of valid encodings [config\/encodings.php]","file":"\/Users\/loranger\/Sites\/projects\/myproject\/vendor\/netson\/l4gettext\/src\/Netson\/L4gettext\/L4gettext.php","line":66}}
Of course, now I know where to fix it, but I think that would be really helpful if l4gettext would detect the current encoding. Maybe “the awesomeness” would be to generate the config.php depending on the environment : I think about the current system locale (or the locale defined in app.php), the current encoding, the textdomain (maybe the current project name ?), the author, etc... What do you think ?
I got another question unrelated to this issue : How can we use the comment tag ? I saw there is an option in the config file, but I cannot figure how I can add it in my blade templates. Can you drop me some clue, please ?
Hey, thanks for testing this again for me! The message you are seeing now makes sense, in that you would still need to update the (published) config file with your desired defaults. I'll see if I can at least issue a warning when executing the fetch command, that the current default settings won't work and that you need to update them.
Automatically changing them seems like a nice feature to increase the useability, so I'll see what I can do there.
As for your question about the comments tag: this can be used to add comments to your po file as a tip or to provide context to your translators. I found a useful post on SO about this very topic which may be of help to you: http://stackoverflow.com/questions/7665274/gettext-automatic-comments-generation
My question was more about Blade : I was wondering how to add such comments but I dug a little and found
{{-- TRANSLATORS: the note --}}{{ _('My string.') }}
or
{{ /* TRANSLATORS: the note */ _('My string.') }}
worked perfectly.
Maybe you could drop an example in the How does it work part ?
Otherwise, _('0% fee')
for example can be translated using poedit, but cannot be saved as mo because of the php-format used with xgettext... I have to remove this comment from the po file in order to get the mo compiled, but it more sounds like a gettext issue rather than a l4gettext's one.
Good idea! I will update the docs together with the update which will hopefully ease the installation process! :+1:
Hey loranger, I just released version 1.4 which has the added documentation regarding the translator comments, and more importantly, I created an install command which hopefully auto-detects your system default locale/encoding and sets those in your config file; this should solve the issue you were experiencing earlier.
Please let me know if you run into any more issues and thanks for your feedback! Much appreciated! :)
PERFECT :+1: Everything works flawlessly. That's now a translation dream ! :wink: Thank you so much for this useful package !
You're welcome! :smiley:
Hello,
I have a same problem :
The given locale [en_US] could not be set; it seems it does not exist on this system
And, I try
php artisan l4gettext:fetc
But, i have an error :
[Netson\L4gettext\FetchCommandNotSupportedOnWindowsException] The fetch command requires the cli command 'locale' to be available; this is not available on a windows system
Thank you for help
The error message suggests you are running the package on a Windows machine, is that correct? The specific command doesn't work on windows as it requires the "locale" command, which is not available on windows systems. If you wish to select or install locales on a windows system, you will have to prepare these in advance. For example, check out this link
I did a "locale -a", and I found in the list
En_US En_US.utf8
And yet I still have the mistake
I dont understand the example
Are you running on Windows? As described in the docs, the command does not work on windows; I haven't tested it on windows and do not intend to officially support windows. If you're running on Linux, I can take another look at it. Happy new year!
Hello, I have an issue right after the l4gettext installation on my mac. Here is what I did :
Composer version 3677c1ea6905b71daf8c3c4af716d2fe2d6f85bd 2014-05-03 07:46:50
)composer create-project laravel/laravel myproject
)composer require "netson/l4gettext:1.3.*"
)Until there, everything is perfect. Then I add the Service Provider and try to check artisan :
I use zsh on a french osx :
Even if I change the locale in config/app.php, I still have this error message. Did I miss something ?