I planed to create Departmental Store Laravel Web Application in Tamil Language Not Using English. How to do it?
You can create web apps using laravel's Localization.
For that, you need to create language strings. Language strings are stored in files within the resources/lang directory.
You need to create locale:
Route::get('welcome/{locale}', function ($locale) {
App::setLocale($locale);
//
});
Then create file within that directory and save it messages.php name like this:
<?php
return [
'welcome' => 'Welcome to our application'
];
?>
Then you need to use this as in any blade file like:
#lang('messages.welcome')
Also, please read the laravel docs from here:
enter link description here
In your encoding defined at DB and front end use - UTF-8 encoding which supports most of the international languages
Related
Currently, I've got the following route in my web app.
Route::get(__('routes.account.dogs'),
[DogController::class, 'index'])->name('dog.index')->middleware('auth');
I specify the URL translation for the route in two different language files.
return [
//Account
'account' => [
'dogs' => 'honden',
]
];
When I send a queued email with this link, I want to translate the link on the user's locale (saved in the database). So I want to get this route based on the user's locale, but app()->setLocale($user->locale); cannot be used because it's a queued job. How can I fix this?
In a perfect world it would be something like:
route('dog.index', [], $user->locale);
laravel __() helper function also accepts the optional 3rd argument $locale for setting the locale to translate.
So you could use the $user->locale in the helper as follows.
url(__('account.dogs', [], $user->locale));
As #Vincent Decaux suggested, you need a library to make your life easier. You could use the one they use or the one I use arcanedev/localization.
Once you set a middleware, everything will be taken care of. But I am concerned regarding your comment:
Yes indeed! but then I still need to do something with the domain. For example .de or .com
Why not use the current domain (.com?) and simply add a directory /en or whatever locale you need instead? It seems inconvenient to me to change the entire domain.
When you use Mail::to(), you can use locale() to choose the translation
Mail::to($user->email)
->locale($user->locale)
->queue(new YourEmail());
https://laravel.com/docs/9.x/mail#localizing-mailables
As in the laravel documentation I have configured my application as below to change languages.
Created sub-directories inside the resources lang folder with each directory contain a messages.php file with relevant languages. Like below
/resources
/lang
/si
messages.php
/ta
messages.php
Then made a get route as in the documentation and it's same as in the documentation
Route::get('change-lang/{locale}', function ($locale) {
if (! in_array($locale, ['en', 'si', 'ta'])) {
abort(400);
}
(dd(App::getLocale()); // this gives me the default lang en
App::setLocale($locale);
// (dd(App::getLocale()); // this gives me the setted language
});
This is the first time I'm using this setLocale() method. Usually, I used to change the language via passing additional parameters with each route and when I did it it's working fine. But I want to make new application with setLocale() method since it is very easy to woking. So I have done everything according to the documentation but still, the language doesn't get changed.
Can anybody please help me to fix this.
I want to set locale for change language but my project is not website but it is a Facebook bot which developed through base controller, I want Example thank.
The default language for your application is stored in the config/app.php configuration file. Of course, you may modify this value to suit the needs of your application. You may also change the active language at runtime using the setLocale method on the App facade:
Route::get('welcome/{locale}', function ($locale) {
App::setLocale($locale);
//
});
see more in https://laravel.com/docs/5.7/localization#introduction
I am a Drupal dev and new to code-igniter or any such php frameworks.
Now i have to modify an existing application done on codeigniter and the structure must be as follows:
example.com/motors
example.com/motors/car-for-sale
example.com/motors/car-for-rent etc.
Before it has only one url example.com/motors and i want to create more urls as mentioned above.
In the application\views\content folder i have the following structure:
application\views\content\motors.php
application\views\content\motors
application\views\content\motors\car-for-sale.php
In the application\controller folder i have the following structure:
application\controller\motors.php
application\controller\motors\motors.php
application\controller\motors\car-for-sale.php
I want to get the url example.com/motors & example.com/motors/car-for-sale from the files resides in the motors folder.Also how can i set a default file to load when i open example.com/motors?
You can't have a (controllers) directory that matches the name of a controller class at the same level. That is, since you have a controllers/motors.php, the files under controllers/motors/* will never be reached.
Instead (and this is the answer to your second question), you should set the default_controller name and rename controllers/motors.php to controllers/motors/<default_controller>.php.
Note that the default_controller setting points to a controller name (not a file location) and is applied to all directories. That is, if you set it to 'Default', then controllers/Default.php will be used when you open http://domain.tld/ and controllers/motors/Default.php will be used if you open http://domain.tld/motors/.
Also, your controller names MUST start with a capital letter, so default.php would be incorrect and should be Default.php instead. This might be working for you on Windows right now (because of its case-insensitive file system), but as soon as you upload your site to a Linux (or other UNIX-based) host, any classes with file names that don't start with a capital letter won't work.
It looks like you're trying to build a CodeIgniter site with a completely different paradigm from what it is designed around.
The structure you are after can be set up using the routes.php file within application/config
In there, you can set routes to go to any location needed, so for you, something like:
$routes['motors/cars-for-sale'] => 'motors/cars_for_sale';
$routes['motors/cars-for-rent'] => 'motors/cars_for_rent';
Then in application/controller you'd have a Motors.php file, which starts:
class Motors extends CI_Controller{
And also has the functions cars_for_sale and cars_for_rent
The mappings in routes sets this to link together.
In order to get the views you want for any given route, in the controller function, you'd have:
$this->load->view('path/to/view/file', $array_of_data); // view path does not need the .php extension
I'd recommend having a look and possibly even a follow through of the CodeIgniter tutorial in their documentation
According to official documentation:
The filename of the translation files is also important: each message file must be named according to the following path: domain.locale.loader:
I must to name all files such as messages.en_US.php, navigation.en_US.php, admin.en_US.php etc. and place in some folder.
i18n\
admin.en.php
messages.en.php
navigation.en.php
admin.fr.php
messages.fr.php
navigation.fr.php
But my project structure should follow the following structure:
i18n\
en_US\
admin.php
messages.php
navigation.php
fr_FR\
admin.php
messages.php
navigation.php
So how to configure symfony2 to support my structure and use translations in common way:
echo $this->get('translator')->trans('hello', array(), 'messages');
It is possible, you have to load resources calling the addResource() method.
$translator->addLoader('php', new PhpFileLoader());
//Inside a loop:
$translator->addResource('php', 'path/to/messages.php', $locale);
Here is the documentation
https://symfony.com/doc/4.1/components/translation.html#loading-message-catalogs
This is not possible. If you want to use Symfony, stick to the conventions from Symfony!
To be correct: It's not possible in a simple way. You would need to write your own translator component and throw the translator component from Symfony away..