![]() We will be able to use it with PHP's exec function. ![]() Once this is done, you have access to xgettext commands. I will not explain it here for every case, if you are using ubuntu server just like me, simply use this command : apt-get install gettext Well, we just have to use exactly the same tool POEdit uses : the xgettext linux command.įor this, you have to install it on your development environment. po files with all of the static texts that are currently written in our project ? */ public function handle () Ģ - Generating and updating. app/Console/Commands/TranslationsParseBladeTemplatesCommand.php You can also update it and put it in the "lang" folder if it makes more sense to you.Įnough talk, here is the file! Just put it in the app/Console/Commands directory and you're good to go : You'll see that I put the resulting files in a "blade-translations" folder at the root of the resources folder.But you are free to modify it on lines 88-99 and 129. I have separated them in the resulting files too so it can be used in different PO domains. Directory structure : I use different folders at the root of my views templates (one for frontend and one for backend).I only use '_i()' and '_n()' functions but if you use others, you can configure them on line 29. I made the parsing customizable for the functions you are using.I'm just going to explain a few things here : I will not explain here all of my script, as it is a little bit complicated, so I will just give the whole file for you. If you are not using blade, you can skip this part and go to the second part. It now just takes a few seconds to parse my blade files, update translations and update my PO files with all my project's translations.ġ - Parsing blade templates to make "blade translations files" So I took a little time to think about it and I found a way to handle all of this myself with just a simple artisan command. So everytime you change a few static strings in your project, you have to download all your files, and then wait for POEdit to parse all of them. po files, I now have to download all my files locally to be able to parse them with POEdit.Īnd thirdly, POEdit parsing is REALLY slow. Secondly, I have started to work remotely, on a development server accessed throught SSH. Therefore, when they are, they are referenced in the PO file with a hash, so it's not very easy to find in which file the original string is located :Įnter fullscreen mode Exit fullscreen mode You have to use the views:cache and views:clear commands to update this folder and I don't really know how it works, but I sometimes have old texts that are still there, or new texts that are not. It works fine too, but it has a few issues. ![]() Parse the views generated by laravel in the storage/framework/views folder.Except for one case : if you have translations inside HTML attributes, for instance : => this text wouldn't be catched by the parser. Well, yes it's cheating, but it works quite well. Manipulate the configuration of the parser to make it believe that files are written in Python.I found two ways on the Internet to handle that, but none of them was perfect: po files.įirst, the POEdit parser for PHP files doesn't understand the blade syntax. ![]() po files, and I found the laravel-gettext package which did everything that I needed.īut I quickly came upon two different problems that made my life harder with. So when I started using Laravel, I naturally looked for something to use. po files for the translation of the static texts of my templates. You surely know that the process of translating a whole website can be pretty difficult.
0 Comments
Leave a Reply. |