Doing Multilingual or localizaiton in Laravel

লারাভেল মাল্টিলিঙ্গুয়াল ওয়েবসাইট করার প্রসেস টা বেশ সহজ

মাল্টিলিঙ্গুয়াল বা লোকালাইজেশন বলতে যেটা বোঝাচ্ছি তা হচ্ছে আপনার website এ আপনি চাইলে এমন ব্যাবস্থা করতে পারেন যাতে কোন ভিসিটর site এর ভাষা তার প্রয়োজন মত পরিবর্তন করতে পারে।

উদাহরন ঃ bikroy.com

এটা হতে পারে একটা Dropdown বা link এর মাধ্যমে । অনেকে তা subdomain দিয়েও করে থাকে

লারাভেল এ কিভাবে করা হয় তা একটু একটা ছোট প্রজেক্ট দিয়ে করার চেষ্টা করি

composer create-project –prefer-dist laravel/laravel multilang

আমাদের এই নতুন প্রজেক্ট টা হল multilang

আমাদের যে resources/views/welcome.blade ফাইল টা আছে আমরা  ওটাকে edit করে সামান্য কিছু লিখা দেই

<html>
    <head>
    </head>
    <body>
         <h1>Welcome</h1>
I would like to say something. It could be anything i need

</body> </html>

আমাদের কাজ হবে আমারা যখন localhost/multilang/public/en লিঙ্ক এ যাব তখন যেন English দেখায়

এবং localhost/multilang/public/bn এ গেলে যেন বাংলা দেখায়

Language Files

লারাভেল এর বিল্ট ইন কিছু Translation ফিচার আছে যেটা দিয়ে আমারা অনেক কিছু করে নিতে পারি ।

ওয়েব সাইট এ লাংগুয়েজ সাধারনন্ত কিছু lang ফাইল এর মধ্যে লিখে রাখা হয়। প্রতিটি ভাষার জন্য আলাদা আলাদা lang file অথবা folder রেখে দিতে হয়। লারাভেল এ এই ফাইল গুলো থাকে – resources/lang/* এর ভেতর। এখানে উল্লেখ্য লারাভেল ২ রকমের language ফাইল সাপোর্ট করে।

১) Raw PHP array – এই ফাইল গুলো দেখতে এমন

<?php
return [
   'greet' => 'স্বাগতম',
   'msg' => 'আমি এখানে কিছু বলতে চাই। আমার যা প্রয়োজন তাই',
   'link' => "এখানে ক্লিক করুন"
];

২) json array – এই ফাইল গুলে দেখতে এমন

{ 
     "Welcome": "স্বাগতম", 
     "I would like to say something. It could be anything i need": "আমি এখানে কিছু বলতে চাই। আমার যা প্রয়োজন তাই",
     "Click Here": "এখানে ক্লিক করুন"
}

দুই ভাবেই আপনি কাজ করতে পারেন তবে এই লিখাতে আমি json ব্যাবহার করবো। এর শুবিধা হচ্ছে আপনি খেয়াল করবেন json এর key এবং value দুটাই হচ্ছে আমাদের string টা। এতে মনে রাখার সুবিধা এবং কোন ট্রান্সলেসন যদি missing থাকে তাহলে সে অর্থহীন কোন key না দেখিয়ে তার English string টা দেখাবে

আমরা শুরুতেই ২ টা json file তৈরি করে ফেলি resources/lang এই ফোল্ডার এর মধ্যে ফাইল গুলো হলো

en.json and bn.json

আমাদের view file এ ফেরত যাই এবং লিখা গুলোকে রিপ্লেস করে @lang(”) ব্যাবহার করে লিখি

<html>
  <head>
  </head>
  <body>
    <h1>@lang('Welcome')</h1>
@lang(‘I would like to say something. It could be anything i need’)

<a href=”http://www.google.com”>@lang(‘Click Here’)</a>

</body>

</html>

এখন localhost/multilang/public এ গেলে আমরা আমাদের পুরনো লিখা গুলো দেখতে পারব কারন by default লারাভেল এ en সেট করা থাকে তাই আমরা এখন যদি লাঙ্গুয়ায়েজ query করি তাহলে English লিখা গুলো পাবো।

Cap2ture

আমরা জদি ভাষা পরিবর্তন করতে চাই তাহলে config/app.php এখানে

'locale' => 'en',

change করে

'locale' => 'bn',

এবার রিফ্রেশ দেই

Capture

Installing Mcamara Vendor

আমাদের site এখন ২ ভাষায় কাজ করতে পারে। এখন এই ল্যাংগুয়েজ লিঙ্ক এর ভিত্তিতে change করতে আমাদের একটা আলাদা vendor এর প্রয়োজন হবে ।

composer require mcamara/laravel-localization

এই ভেন্ডর টার github page documentation টা দেখে নিবেন

vendor install হয়ে গেলে config/app.php ফাইলে provider এবং alias ঠিক করে দিবেন

        'providers' => [
		// [...]
                Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class,
        ],

 

        'aliases' => [
		// [...]
                'LaravelLocalization' => Mcamara\LaravelLocalization\Facades\LaravelLocalization::class,
        ],

এখন command line এ যেয়ে

php artisan vendor:publish --provider="Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider"

এতে config folder এর মধ্যে laravellocalization নামে একটা ফাইল তৈরি হবে। অই ফাইল টা তে জেয়ে

//'bn' => ['name' => 'Bengali', 'script' => 'Beng', 'native' => 'বাংলা', 'regional' => 'bn_BD'],

খুজে বের করুন এবং কমেন্ট  উঠিয়ে দিন, এবং স্পানিশ “es” লাইন টা কমেন্ট করে দিন

'bn' => ['name' => 'Bengali', 'script' => 'Beng', 'native' => 'বাংলা', 'regional' => 'bn_BD'],

 

Making the language selector

আমাদের ব্লেড ফাইল এ

<ul>
   @foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
     <li>
         <a rel="alternate" hreflang="{{ $localeCode }}" href="{{ LaravelLocalization::getLocalizedURL($localeCode, null, [], true) }}">
         {{ $properties['native'] }}
         </a>
     </li>
   @endforeach
 </ul>

এতে ভাষা পরিবর্তন করার লিঙ্ক তৈরি হবে। আমাদের এখন একটা middleware বানাতে হবে যা এই লিঙ্ক এ ক্লিক করলে ভাষা পরিবর্তন করতে পারবে

app/http/kernel.php এই ফাইল এ $routeMiddleware array টাতে কয়টা লাইন যোগ করুন

'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class, 
'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class

এবার আপনার route ফাইল এ একটা route group তৈরি করুন

 

Route::group([
 'prefix' => LaravelLocalization::setLocale(),
 'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]
 ], function() {

    /** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP * */
     Route::get('/', function () {
        return view('welcome');
     });
     
     Route::get('/translated', function () {
        return view('translated');
     });

});

Route::get('/other', function () {
    return view('other');
});

এখন এই route groupএর মধ্যে যে সকল route declare করা হয়েছে সেগুলে লারাভেল ভাষা পরিবর্তন করবে।

আর বাইরের গুলোকে করবে না। আপনার form submit, ajax, post requests, গুলোকে এখানে রাখতে পাড়বেন

Lets Test

টেস্ট করার জন্য আমি আরও কিছু পেইজ বানিয়ে নিলাম কিছু বিষয় দেখবার

আমি একবার বাংলায় switch করলে সে আমাকে যে দুটো পেজ route group এর ভেতর সেগুলো বাংলায় দেখায় এভাবে আবার english switch করলে আমার সাইট এর যে সমস্ত লিঙ্ক route group এর ভেতর ওগুলে english এ দেখাবে এবং লিঙ্ক এর মাঝে /en অথবা /bn দেখাবে

আর যে লিঙ্ক আমাদের route group এর বইরে তার কোন পরিবর্তন হবে না

27mv85

Download

পুরে প্রোজেক্ট টা ডাউনলোড করুন এখানে

multilang.zip

 

Advertisements

How to get custom domain names instead of localhost with xampp on windows

It is quite simple to turn your development urls like http://localhost/ibikri/ into http://ibikri.tes/ or http://ibikri.com/

It makes for a clean url when we are developing. And also allows you to work with actual urls instead of localhost or 127.0.0.1. This is quite handy for some situations.

Capture

Now before you begin, you should know what we are about to do

I am going to change windows hosts file to redirect that domain to localhost. So basically when you hit ibikri.com it would redirect you to localhost .This leads to a simple problem- “what happens if i wanna visit the actual ibikri.com?

This is why it is recommended to not use actual tlds on virtual hosts. Say instead of using ibikri.com you can use ibikri.localhost or ibikri.test or ibikri.vcom. It is upto you just try to avoid the tlds “*.dev  and *.foo” these tlds will not work with google chrome or firefox

I would recommend you see a this list of suggested domain extensions .

Step 1: Find and edit your hosts file. In windows it is located at

C:\Windows\System32\drivers\etc

Go to the bottom of the file and add this line

127.0.0.1 yourdomain.test

Here replace “yourdomain” with your sites domain duh!

Now in your apache folder find the httpd-vhosts.conf file for xampp it is located inside

xampp\apache\conf\extra\httpd-vhosts.conf

You should find a couple of tags in this file that is commented with ##. I recommend you copy 1 of those and uncomment it. And then replace the values. It would look something like this

This example is assuming your project is inside “yourfolder” inside xampp/htdocs. If it is inside htdocs directly just remove the /yourfolder

<VirtualHost yourdomain.test> 
    ServerAdmin webmaster@yourdomain.test 
    DocumentRoot "/xampp/htdocs/yourfolder"
    ServerName yourdomain.test 
    ServerAlias yourdomain.test 
    <Directory "C:/xampp/htdocs/yourfolder"> 
        Require local 
    </Directory> 
</VirtualHost>    

ok the reason why i recommend you copy one of your existing commented VirtualHost tag and edit it instead of copying this is the directory structure and syntax may be a little different in your version of apache.

 

We are done. Now just restart your apache server and you will be able to visit your local development server at localhost/yourfolder by typing

http://yourdomain.test/

in your browser.

Hope this helps someone. I learned how to do this from stackoverflow. If you want you could check this out, and this and maybe show them some gratitude by voting their answers :).

 

 

Blade Of Darkness , Blade of Light MOD Temple of Ianna

 

The view of Ianna’s temple with the Blade of Light MOD. I apologize for the choppy frame rate. This is my first game recording. I do not have a powerful PC either.

Blade of Light is a HD texture and gameplay modification for the classic 2001 hack n slash game Severence : Blade of Darkness.

Blade of Darkness is my all time favorite hack and slash game. I havent played this in a while. The game is very interesting fighting system. Which is at the same time hard and effective once you know it. Unlike most hack and slash games where you just smash the attack keys you have to follow a certain move and attack combination to deal a great deal of damage. Poking around the enemy is no good. Where as putting some combo enhances your attack A LOT.
This time i wanted to try with a new MOD. Blade of Light MOD (works with GOG version too)

watch the official video (much better quality than mine)-

http://www.moddb.com/mods/blade-of-light

Enhanced gameplay where lighting plays a part in the strategy. Use the light bearing blades to slice your way into the heart of the Darkness. For any fan of BOD this MOD is a must to try. It does not tamper with the combo system which makes it comfortably familiar.

The contrast of light and dark is just great. The dark dungeons and tunnels are just more scary and difficult to cross, since you see nothing. And its impossible to look at an archer who is standing in front of the sun, the light blinds you.

An already difficult game is just much more difficult with this MOD. You can turn off the blooming effect anytime if you are having trouble crossing a particular section

DIY hot knife

I bought some plastic boards from New market last weekend. I say plastic board cause thats the only name the shop keeper could tell me. I think its a closed cell polyethylene board. I am probably wrong. but the properties are similar. Its hard, its relatively light but approximately 10 times heavier than Styrofoam and does not bend. It breaks before deforming.

2015-02-25 13.48.12
Plastic Board. Source: ABC Stationary New Market, Dhaka

 

They are pretty strong but i was able to make a clean cut with a Utility knife just as the shop keeper told me. But it takes a lot of patience and skill to make a clean cut and large shapes are just that difficult to pull off.

2015-02-25 13.48.59
Recommended cutting tools by shop keeper

 

As always the lazy mind has a tendency to look for easier ways. And I came across “heated knife” the tool used to cut this type of materials with ease. I tested the concept by heating some Utility Knife blades using fire and it worked.

Unfortunately i dont have a heated knife lying around. Googling around looking at how it works I thought it would be relatively easy to make one using a soldering iron.

I have this pretty “old” soldering iron with wooden handle and large tip. Since I have a spare i decided to make a knife out of it.

2015-02-25 11.40.32
Flattened Soldering Tip with some sanding to sharpen the edges.
2015-02-25 11.39.44
How thin it is from the side

 

 

 

 

 

 

 

 

 

 

The method I used is simple. I heated the soldering iron tip high and then hammered it to make a flat shaped head.

Once I was satisfied with the hammering a little sanding gave the edges some sharpness.

CAUTION: Using hot knife to cut plastic will release hazardous fumes. Try not to breath on them.

I tested the knife on a piece of board.

2015-02-25 11.32.47
Hand cut plastic board using home made hot knife

 

Although it wasnt like cutting butter. But it was definitely close to cutting vegetables 🙂 . I managed to cut a square board with smooth edges in less than a minute. It takes a while to get the tip heated. And perhaps due to its extended surface it looses heat faster and needs a break after cutting a while.

The edges are relatively smooth as well. You can make the edges better by slicing off the extra melted drops of plastic with a knife.

2015-02-25 11.33.09
Rough margins but smooth ends.

I am pretty impressed by the results, I will surely use this new plastic board for my future prototypes. I cant wait for the weekend to get around. 😉 .

 

DIY Thermo Electric Air Cooler

I made this thermoelectric air cooler a while back, almost forgot about them. I was clearing out my smartphones memory and found some image. So decided to post the idea here.

Things you need:

1 peltier device (Thermo electric cooler) I got this from china courtesy of a friend Bijoy
http://www.aliexpress.com/wholesale?SearchText=thermo+electric+cooler&opensearch=true

2015-02-25 12.23.20

 

2 CPU AMD cooler (any square shaped model but both same size preferred) I am not sure what model I used I just went to elephant road and got the cheapest available. Costs 100tk each From Elephant road. I bought 3

amd_3200_top

 

Heat sink compound. Found elephant road as well not sure about price 10tk per pack i guess. Also you get some compound free wit the CPU heat sinks.

Voltage source. I am using CPU power supply Any old atx power supply will do.

ATX-powersupply

 

Some thin wire to bind the coolers
Apply some heat sink compound to the peltier and place it on 1 of the heat sink.

Apply more compound and put the other cpu cooler on top.

Make sure both cooler has the same orientation. The aluminium fins must be horizontal to each other.

It should look something like this-

2014-09-28 09.36.21

hold the 2 coolers on place tight and attach them using a thin wire rounding through the heat sink fins. Or if you can find appropriate nuts and bolts use them.

wire join

 

Yellow marks show wire joining the 2 heat sinks.

Connect the 3 red wires together, do the same for the black.

Red is 5v, black is ground and yellow is signal for CPU cooler. In my model the signal was optional so I didnt use them.

since we are connecting 3 in parallel same voltage will be maintained in 3.

If you have a power supply connection pin thats a good thing. otherwise just add the power and the ground to a power cable manually.

Same way ground is black in most power supply cables. and red is 5v.

The cooler was working good. I can feel the cold side getting cool in less than a minute. The heat generated on the other side is very high on the other hand.

you can use this cooler in a lot of applications. I was planning to use an array of these things to make asealed box computer casing( air conditioned) no dust but cool.

The cold air coming out of the heat sink is pretty soothing . Feels like putting your hand before an AC at 26*

The peltier looses its efficacy if the hot side is too hot. So the heat sink on the hot side is more important. And use of larger heat sink will increase overall performance.

I have seen a video on youtube someone making a box out of Styrofoam (Shola) and place this on the wall to make a mini freezer.

Feel free to comment your ideas.