php වැඩ්ඩො පුලුවන්නම් මේක කරන විදිය කියල දියන්

bornunlucky

Well-known member
  • Oct 31, 2018
    550
    552
    93
    මචං මෙහෙමයි.

    1 හදන්නන Folder එකක් my_app කියල.
    2 ඒකෙ ඇතුලෙ තියෙනව index.php කියල file එකක්. ඒකෙ content එක තියෙන්නේ මෙහෙමයි.

    PHP:
    <?php
    
    echo 'hello machan 01';
    
    ?>
        
    <p>hello machan 02</p>

    3 දැන් ඔය my_app කියන Folder එක ඇතුලට ගිහින් මෙන්න මේ Composer package එක Install කරන්න.
    composer require symfony/translation මේකෙ docs https://symfony.com/doc/current/translation.html#installation

    දැන් මට කියල දියන් මචං ඔය index.php එක ඇතුලෙ තියෙන hello machan 01 සහ hello machan 02 කියන text strings ඔය Install කරපු package එක යූස් කරල translate support කරන විදියට හදාගන්න.

    මේක php වල namespaces, interfaces ගැන දන්න කෙනෙක්ට පට්ට ලේසියෙන් කරන්න පුලුවන්.
     

    topkollek

    Well-known member
  • May 22, 2014
    44,201
    1
    58,571
    113
    ┬┴┬┴┤(·_├┬┴┬┴
    ඔය වගේ දේවල් තනියෙම කරල ඉගෙන ගන්න ඕනෙ. කරගන්නම බැරි උනොත් ඔයා කරපු පියවරවල් දැම්ම නම් දන්න කෙනෙක් උදව් කරයි.
     
    • Like
    Reactions: hasithayad

    hasithayad

    Well-known member
  • Sep 28, 2011
    30,792
    1
    45,001
    113
    උඹ හිතුවද පොඩ්ඩක් අවුස්සල තිව්වම උඹ වෙනුවෙන් සම්පූර්ණ කෝඩ් එකම ලියල දෙයි කියල.

    ඕක තනියම කරපන්. ඊට පස්සෙ අවුලක් ආවොත් මේකෙන් අහපන්. නිකන් අනුන්ගෙ කෝඩ් ලිය ලිය ඉන්න කාටවත් අමාරුවක් නෑනෙ
     

    bornunlucky

    Well-known member
  • Oct 31, 2018
    550
    552
    93
    උඹ හිතුවද පොඩ්ඩක් අවුස්සල තිව්වම උඹ වෙනුවෙන් සම්පූර්ණ කෝඩ් එකම ලියල දෙයි කියල.

    ඕක තනියම කරපන්. ඊට පස්සෙ අවුලක් ආවොත් මේකෙන් අහපන්. නිකන් අනුන්ගෙ කෝඩ් ලිය ලිය ඉන්න කාටවත් අමාරුවක් නෑනෙ

    කෝඩ් එකක් ලියන්න නෑ බන්. කරන විදිය ඇහුවෙ?
     

    mr90486

    Well-known member
  • Sep 2, 2008
    1,705
    1,476
    113
    Everywhere
    just require composer's autoload.php from index and follow the documentation. For example,

    require 'vendor/autoload.php';
    use Symfony\Contracts\Translation\TranslatorInterface;

    set the config

    call the translator method

    echo it out

    Lazy to type this out ban
     
    • Like
    Reactions: bornunlucky

    chinthaka156

    Well-known member
  • Jun 26, 2008
    3,744
    4,834
    113
    එලකිරි හන්දිය
    පහල තියෙන ක්ලාස් එකේ ඔබ්ජෙcට් එකක් හදල ට්‍රාන්ස්ලේටර් එක කෝල් කරහන්. එතකොට ට්‍රාන්ස්ලේට් කරපු ස්ට්‍රින් එක රිටර්න් කරයි.

    Symfony\Contracts\Translation\TranslatorInterface;

    $translated
    <?php

    $translator = new TranslatorInterface();

    echo $translator->trans('hello machan 01');

    ?>

    <p><?php echo $translator->trans('hello machan 02'); ?></p>


    just require composer's autoload.php from index and follow the documentation. For example,

    require 'vendor/autoload.php';
    use Symfony\Contracts\Translation\TranslatorInterface;

    set the config

    call the translator method

    echo it out

    Lazy to type this out ban


    ela ela ela bro
     

    bornunlucky

    Well-known member
  • Oct 31, 2018
    550
    552
    93
    පහල තියෙන ක්ලාස් එකේ ඔබ්ජෙcට් එකක් හදල ට්‍රාන්ස්ලේටර් එක කෝල් කරහන්. එතකොට ට්‍රාන්ස්ලේට් කරපු ස්ට්‍රින් එක රිටර්න් කරයි.

    Symfony\Contracts\Translation\TranslatorInterface;

    $translated






    ela ela ela bro

    මචං ඔහොම කරන්න බෑ Interfaces instantiate කරන්න බෑ බන්.
     

    bornunlucky

    Well-known member
  • Oct 31, 2018
    550
    552
    93
    දැන් තොපි මට මේක කියල දෙන්නෑනේ....? හෙන බලුයි ඕයි තොපි නම්. :growl::angry:
     

    bornunlucky

    Well-known member
  • Oct 31, 2018
    550
    552
    93
    තේරෙන්නෑ හුත්තෝ...........

    PHP:
    <?php
    
    require_once 'vendor/autoload.php';
    
    use Symfony\Contracts\Translation\TranslatorInterface;
    
    class Hello implements TranslatorInterface {
    
        public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null) {
    
        }
    
    }
    
    $obj = new Hello;
    echo $obj->trans('hukanawane ithin');