how to load Register form lables caption from other language file?

Viewed 21

i have create a twig registration form. i want to make all labels caption variable to be changed as per user language. my language file is seperated in PHP file, please how to load all variables from language PHP file to the template .twig file ??

and here is a form :

{{ header }}
 <h5> {{text_heading}} </h5>
 <p> {{text_register}} </p>
 <form action="{{ action }}" method="post" enctype="multipart/form-data">

    <label for ="fulltname"> {{entery_fullname}} </label>
    <input type="text" name ="fullname" value="{{ username }}" placeholder ="{{place_fullname}}"> <br><br> </input>

    <label for ="email"> {{entery_email}} </label>
    <input type="email" name ="email" placeholder ="{{place_email}}"> <br><br> </input>

    <label for ="phone"> {{entery_phone}} </label>
    <input type="phone" name ="phone" placeholder ="9xxxxxxxx"> <br><br> </input>

    <label for="password">{{ entry_password }}</label>
    <input type="password" name="password" value="{{ password }}" placeholder="{{ place_password }}" />

    <input type="radio" name ="usertype" value = "customer" checked>
    <label > {{Text_Customer}} </label>

    <input type="radio" name ="usertype" value = "vendor">
    <label > {{Text_Vendor}} </label>

    <input type="radio" name ="usertype" value = "both" >
    <label > {{Text_Both}} </label>
    <br> <br>

    <button name ="register" type ="button"  method ="submit"> {{btn_register}} </button>
    <p> {{text_forgotten}} </p>

</form>
{{ footer }}

my language file is PHP, and here it is:

<?php
// Heading
$_['heading_title']  = 'Administration';

// Text
$_['text_heading']   = 'Administration';
$_['text_register']     = 'Please enter your details to register.';
$_['text_forgotten'] = 'Forgotten Password';
$_['Text_Customer'] = 'Im a Customer';
$_['Text_Vendor'] = 'Im a Vendor';
$_['Text_Both'] = 'Both Customer/Vendor';
// Entry
$_['entery_fullname'] = 'Your Full Name: ';
$_['entery_email'] = 'Email: ';
$_['entery_phone'] = 'Phone No: ';
$_['entry_password'] = 'Password: ';

// Button
$_['btn_register'] = 'Register';

// placeholders
$_['place_fullname'] = 'Your Real Full Name';
$_['place_email'] = 'Active Email';
$_['place_password'] = 'Strong password';
// Error
$_['error_register']    = 'Check your input carfully.';
$_['error_token']    = 'Invalid token session. Please register again.';
?>
2 Answers

i fix the proble: first i convert twig file to php file and i use (define) on language file like this:

define('entery_fullname', 'Your Full Name:');

but my question now, is this way is better or there is somthing else more faster and much better?

You should use twig filters for this. Register a filter trans and use it like:

{{"phrase|trans}}

Then you would use own or third party implementation (like symfony/translations) to load and translate phrases.

Related