Translate text in config folder cakephp 3 - php

I'm trying to internationalize a CakePHP 3 application using cake i18n extract. All the texts coming from src folder are translated fine, but I have some text that I put inside config/bootstrap.php but those don't get translated even though I placed them inside the double underscore function __('My text') and I also generated the translation files in src/Locale folder (the same way I did for the other texts that work.
Any idea why my texts in config/bootstrap.php won't get translated?
Thanks in advance for any help

They do not show up because by default the extract task only looks in the src folder. When running the task it will ask you from what paths to extract, and it should only list the src folder by default.
You can either add your custom paths interactively in the shell when it asks you for the folders that should be looked up, or you can use the paths option to define them in beforehand, like:
bin/cake i18n extract --paths /var/www/app/config,/var/www/app/src
When doing so may also want to use the output option to specify the output path, as the task will use the first path as the root for output, ie with the above paths it would put the files in config/Locale instead of src/Locale. Alternatively you can switch the paths, but then the messages from the config folder files would appear at the bottom of the .pot file.
See also
Cookbook > Console Tools, Shells & Tasks > I18N Shell > Generating POT Files > Extracting from multiple folders at once

It depends on where you set the application locale with I18n::setLocale(). Your application using App.defaultLocale setting to determinate wich language sould be shown.
If you change your language in your controller, your configuration files already loaded so this will not effect on these files just on those files what will be loaded after your setLocale.
Try to change your language before translatable files loaded, or load translate configuration files in controller after changeing the appLocale.

Related

Not a single PHP file is recognized as PHP file in PhpStorm

I really don't know what could cause such a strange behavior from mentioned editor. Literally all project files with .php extension are recognized as... text files I suppose. I know that stuff like that happens when the extension is forgotten during making of a PHP class for example, but I cannot explain why this appended to all files in the project.
I know that I can change file type of each individual class, but I'm doing a Laravel project and I can't manually change file type of every single default PHP class each time when I start a new project and each time I myself add a new class.
Is there any setting which defines rules for certain file types, since changing file types of every individual project file isn't a solution? At least, not viable one.
Every language is associated with one or more file extension patterns within the IDE.
Open File > Settings and then search for File Types and look for PHP in this case. There will be a list of Registered Patterns associated with PHP.
Ensure that *.php is in that list, or add it if it is missing.

Laravel 8 – create route alias for image folder inside public directory

I’m in the middle of the process of replicating a framework that I developed in node / react to laravel. Right now, I’m adjusting the main architecture and currently working on a blade master page.
My original idea (Laravel 8 – use blade asset to display image, but loading from resources subfolder) didn’t work, so I’m trying a new approach to set up how I want my asset files to be served.
The assets in question is basically images for layout purposes. I organized the directory like so:
public/app_files_layout
Inside it, I have a bunch of image files that I want to access. The thing is that I don’t want to access like http://localhost:8000/app_files_layout/image-name.jpg. My intention is to access like: http://localhost:8000/images/image-name.jpg, but I want to maintain the directory names I created intact, so it can have a high fidelity architectural organization similar to my framework that I built in other languages.
I figured that I would set up a simple routing logic for it in Laravel web.php file. I followed the suggestion from this stackoverflow question:
https://stackoverflow.com/a/38736973/2510785
However, when I try to access via browser through the following address http://localhost:8000/files-layout-test/image-name.jpg, returned me an error like so:
The requested resource /files-layout-test/image-name.jpg was not found on this server.
I stripped the code just to try to find out what could be wrong, and this is what I did to debug it:
Route::get('/files-layout-test/{filename}', function($filename){
echo 'debug';
});
The strange behavior is that, when I try to access without the file extension (ex: http://localhost:8000/files-layout-test/image-name), it goes through, but I need the file extension to be there.
Any ideas on how I could get this done?
Note: I’m new to Laravel, so the answer may be simple.
Basically for simple stuff like creating a symlink for public/images and public/app_files_layout you can use the built-in storage:link command.
In your config/filesystems.php file, you can define the symlinks you want to create
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('images') => public_path('app_files_layout'),
],
Then you can run php artisan storage:link and it will create all the symlinks defined the links array in config/filesystems.php. No need to create any custom Artisan command. You can read more at Laravel Docs
With the above symlink created you can use the asset() helper to generate the urls for assets which are actually in public/app_files_layout using asset('images/filename.ext').
You can also access public/app_files_layout/image-name.ext at http://localhost:8000/images/image-name.ext once the symlink is created.
However if you want to add some other logic or say you want to get user input for creating symlinks then you can define your own custom Artisan command using the storage:link command as starting point

Phpdocumentor looks for custom templates in vendor directory

I need to create custom template for PhpDocumentor. The problem is that paths defined in the template.xml, even when specified as absolute ones, are not resolved correctly. PhpDocumentor looks for them in the vendor directory.
<template>
<author>Code Mine</author>
<email>office#code-mine.com</email>
<description>Template for Confluence API</description>
<version>1.0.0</version>
<transformations>
<transformation writer="twig" source="./index.html.twig" artifact="index.html"/>
<transformation query="indexes.namespaces" writer="twig" source="./namespace.html.twig" />
<transformation query="indexes.classes" writer="twig" source="./class.html.twig" />
</transformations>
</template>
Despite fact that twig templates are located in path to which xml refers, I'm getting error that files don't exist.
EDIT:
I have also tried with setting up all configuration details in phpdoc.xml in hope that paths will be considered relative to configuration file but with no luck.
If you specify a custom template with --template="..." it will (for some strange reason) copy that entire template into the vendor folder together with the original templates, and therefore the path structure in template.xml needs to remain the same. You only need to change eg. templates/clean/ to templates/yourtemplatename/.
I have an issue with caching though. I can't get it to reread my template every time. It has cached it somewhere and I can't for the life of me figure out where. Documentation is really bad and source is worse.
Update:
Finally figured out that it cached my template in the temp folder of my computer. For Windows eg.: c:\Users\<username>\AppData\Local\Temp\phpdoc-twig-cache\. So I just delete that entire folder.
Correct me if I'm wrong but it seems like you can just pass a file path on the CLI
https://www.phpdoc.org/docs/latest/getting-started/changing-the-look-and-feel.html
Using a custom template When you have a company or project-branded template you can also use that with phpDocumentor by providing the location of your template’s folder:
$ phpdoc -d "./src" -t "./docs/api" --template="data/templates/my_template"
you may need to back out of the vendors directory with a few ..'s like so
--template="../../data/templates/my_template"
or pass an absolute path
--template="/var/scratch/foo/data/templates/my_template"

Get filenames of assetic files

I'm building a web app using Symfony2 with Assetic. I would like to make a manifest file , but I have to manually add the file names to the list.
I can use PHP to get all static files (in [app/Bundle]/Resources/public), so I can generate of list of those files easily. But the other files (stylesheets, javascripts and images) are being generated by Assetic.
Is there a way to get a list of those generated files, so I can add them to a manifest-file?
All files are registered in router
php app/console debug:router
You can see what the command is doing, by viewing the source: Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php. You can extract what you need.

What's the proper way to work with assets in Yii?

I notice that Yii creates strange set of directories (names like 8523d23 or 10s89b92) in assets directory, and this even happens at runtime. For example, one of my tables got more than 10 records, pagination kicked-in and I got a new files in assets subdirectory named pager.css.
When I move my site from testing to production, should I copy all those, or just create an empty "assets" directory, and it will be filled at runtime?
If I want to add, for example, some new jQuery plugin, how should I proceed?
For example, I wish to add jquery.charcounter.js, do I copy it to assets or to yii/framework/web/js/source? If I do the latter, how do I get this .js file included in HTML page output?
assets should be a writable directory. Yii takes care of assets.
By calling Yii::app()->assetManager->publish() some stylesheets, images, scripts, or even entire directories can be put into a web-visible folder.
pager.css and other non-familiar files are produced by widgets (CLinkPager for example) and other components (such as CClientScript publishes jQuery whenever you need that).
During deployment, this folder should be empty, but it doesn't really matter.
Adding plugins should never be done through framework folders. You can place them either in components dir and publish it runtime if necessary, or into any other convenient visible directory (like as images or css).
Update
To embed jquery.charcounter.js, put it in components directory, then call
Yii::app()->clientScript->registerScriptFile(
Yii::app()->assetManager->publish(
Yii::getPathOfAlias('application.components').'/jquery.charcounter.js'
),
CClientScript::POS_END
);
Regarding weird folder names, I firmly believe they are unique hashes (or part of), so they can be differentiated if application uses several extensions.
This would resolve the query as this provides detailed explanation for the assets folder:
http://www.yiiframework.com/wiki/148/understanding-assets/

Categories