Welcome Guest, Not a member yet? Register   Sign In
Make a normal translation for a site similar to Laravel
#1

A question for developers, you can implement the translation of the application in a similar manner as in Laravel so that you can call a simple function __ ('translation', parameter) from anywhere. Because it’s not very convenient to create arrays of translation, for example, how you implemented


PHP Code:
return [
   'commandNotFound' => 'Команда "{0}" не найдена.',
   'helpUsage'       => 'Использование:',
   'helpDescription' => 'Описание:',
   'helpOptions'     => 'Опции:',
   'helpArguments'   => 'Аргументы:',
   'invalidColor'    => 'Недопустимый {0} цвет: {1}.',
]; 



and do like this




PHP Code:
return [
    
'Uso:'          => 'Использование:',
    
'Descripción:'  => 'Описание:',
    
'Opciones:'     => 'Опции:',
    
'Argumentos:'   => 'Аргументы:',
    
'Inválido {0} color: {1}.'    => 'Недопустимый {0} цвет: {1}.',
]; 

and then call us like this __ ('Opciones:') anywhere
Reply
#2

(This post was last modified: 10-10-2019, 09:27 AM by milengardev1994.)

There are many ways of implementing translations. In fact, in Laravel you can do it also in couple of ways.
You can always create a static helper class e.g TextHelper and based your translations provider call -> TextHelper::getText(translationKey)

In that sense I don't quite feel that need to create a special translation solution in CI.

I hope have understood your point correctly.
Reply
#3

(10-10-2019, 09:17 AM)milengardev1994 Wrote: There are many ways of implementing translations. In fact, in Laravel you can do it also in couple of ways.
You can always create a static helper class e.g TextHelper and based your translations provider call -> TextHelper::getText(translationKey)

In that sense I don't quite feel that need to create a special translation solution in CI.

I hope have understood your point correctly.
the problem is that there are no examples, ways to implement this, so I showed an example of how I did it in 3 versions. So I wrote my own version, I wanted the professionals to finalize it, maybe I did something wrong, can be done much better.
Reply
#4

I am interested with an exemple for translation.
Reply
#5

(This post was last modified: 10-25-2019, 09:09 AM by midav.)

(10-15-2019, 01:57 PM)kris2 Wrote: I am interested with an exemple for translation.
I use a smart template engine and here in the code you can see how the translation should be __ ('Автопарк')
Code:
<div class="content-bk">
    <div class="title-bk">
        <h2>{__('Автопарк')}</h2>
        <a href="/cabinet/autoparck/add" class="btn green"><i class="fas fa-car"></i>&nbsp;&nbsp;{__('Добавить')}</a>
    </div>
    <hr class="separator px2">
    {if count($autopark) > 0}
        {foreach $autopark as $per}
            <div class="staff-li">
                <div class="staff-li-left">
                    {if $per['foto_car'] == ''}
                        <div class="staff-li-left-photo no">
                            <i class="fab fa-mailchimp"></i>
                        </div>
                    {else}
                        <div class="staff-li-left-photo" style="background-image: url({$per['foto_car']})">
                            <img src="{$per['foto_car']}" alt="">
                        </div>
                    {/if}
                    <div class="staff-li-left-info">

                        <div class="staff-li-left-info-bl">

                                <span>{$per['name_mk']} {$per['name_md']} ({$per['year']})</span>

                        </div>
                    </div>
                </div>
                <div class="staff-li-right">
                    <div class="action-select">
                        <div class="action-select-value">{__('Действие')}</div>
                        <ul>
                            <li><a href="/cabinet/autoparck/edit/{$per['id_au']}">{__('Изменить')}</a></li>
                            <li><a href="/cabinet/autoparck/del/{$per['id_au']}">{__('Удалить')}</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        {/foreach}
    {else}
        {__('Нет машин.')}
    {/if}

</div>
this is how the translation file should look
Code:
return [
    'Uso:'          => 'Использование:',
    'Descripción:'  => 'Описание:',
    'Opciones:'     => 'Опции:',
    'Argumentos:'   => 'Аргументы:',
    'Inválido {0} color: {1}.'    => 'Недопустимый {0} цвет: {1}.',
];
Reply




Theme © iAndrew 2016 - Forum software by © MyBB