Hey guys I need help because I am with difficulties on showing the arrays in my website screen.
There is an attachment with my website screen so you can see what kind of error is.

Here it is my UserController.php where I call the translation:

<?php

    class UserController extends \Phalcon\Mvc\Controller
    {

    protected function _getTranslation()
  {

    //Ask browser what is the best language
    $language = $this->request->getBestLanguage();

    //Check if we have a translation file for that lang
    if (file_exists("app/messages/".$language.".php")) {
       require "app/messages/".$language.".php";
    } else {
       // fallback to some default
       require "app/messages/en-US.php";
    }

    //Return a translation object
    return new \Phalcon\Translate\Adapter\NativeArray(array(
       "content" => $messages
    ));

        public function indexAction()
        {
      $this->view->setVar("t", $this->_getTranslation());
        }
    }

?>

Here it is the index.volt where it is the content:

<div class="introduction-section" id="page-top">
  <h1><span class="glyphicon glyphicon-shopping-cart"></span>{{ t_['Do-you-shop-a-lot']  }}?</h1>
  <br clear="all">
  <ul class="explore btn-explore">
    <li><a href="/shop">{{  t_['Shop-Now'] }}</a></li>
  </ul>
</div>
<div class="about-section" id="about">
  <h1>{{ t_['About'] }}</h1>
  <br clear="all">
  <p>{{ t_['AboutDesc']  }}</p>
  <br clear="all">
  <br clear="all">
  <blockquote>{{  t_['blockquote']  }}</blockquote>
</div>
<div class="partners-section" id="partners">
  <h1>Partners</h1>
  <br clear="all">
  <p>Still looking for partners :(</p>
</div>
<div class="services-section" id="services">
  <h1>Services</h1>
  <br clear="all">
  <br clear="all">
  <br clear="all">
  <div class="shop-cart-service">
    <figure>
      <img src="http://mashop.com/img/shop-cart.png" width="35%" />
      <h1>Online Shopping</h1>
      <figcaption>A easy way to shop with a better UI/UX for our clients</figcaption>
    </figure>
  </div>
  <div class="daizpay-service">
    <figure>
      <img src="http://mashop.com/img/dayz-pay.png" width="35%" />
      <h1>Daiz Payment's Gateway</h1>
      <figcaption>A better way to do payments through our online shop</figcaption>
    </figure>
  </div>
</div>
<div class="contact-section" id="contact">
  <h1>Contacts</h1>
  <br clear="all">
  <br clear="all">
  <div class="contacts-form">
    <div class="form-message"></div>
    <form action="" method="POST" class="ajax">
      <label for="nome" class="name-label">Name:</label><br clear="all" />
      <input type="text" name="name" id="name" /><br clear="all" />
      <br clear="all" />
      <label for="email" class="email-label">Email:</label><br clear="all" />
      <input type="email" name="email" id="email" /><br clear="all" />
      <br clear="all" />
      <label for="subject">Subject:</label><br clear="all" />
      <input type="text" name="subject" id="subject" /><br clear="all" />
      <br clear="all" />
      <label for="message">Message:</label><br clear="all" />
      <textarea rows="4" cols="49" name="message" id="message"></textarea><br clear="all" />
      <br clear="all" />
      <input type="submit" value="Send" id="submit" />
      <input type="reset" value="Reset" />
    </form>
  </div>
</div>

And here the en-US.php which is inside of app/messages folder where I have the arrays:

<?php

$messages = array(

  "AboutDesc" => "DaizGroup was thought and createad in 30th October 2016 in Braga. The CEO thought about this to give a easy way to people buy with a better gateway security.
  He thought it wouldn't be worst if our company just do payments of shopping retailing with secure gateways.
  Also we developed a gateway payment, easy and secure, and it works on this website. Our company sells everything from books to anything of technology. This website is also done with the heart of our own CEO and his team for our clients.",
  "Do-you-shop-a-lot" => "Do you shop a lot",
  "Shop-Now" => "Shop Now",
  "About-Us" => "About Us",
  "Partners" => "Partners",
  "Services" => "Services",
  "blockquote" => "Will not be possible if you don't have determination, passion, warrior spirit and never give up. Follow your dreams and wait for the right moment.",
  "SadPartners" => "Still looking for partners",
  "OnlineShopping" => "Online Shopping",
  "DaizGateway" => "Daiz Payment's Gateway",
  "OnlineShoppingDesc" => "A easy way to shop with a better UI/UX for our clients",
  "DaizGatewayDesc" => "A better way to do payments through our online shop",
  "Name" => "Name",
  "Email" => "Email",
  "Subject" => "Subject",
  "Message" => "Message",
  "Send" => "Send",
  "Reset" => "Reset",
  "About" => "About"
);

?>

Any of help would be appreciated.

Thank you.

Hi,

it seems you have indexAction() nested in the _getTranslation() method, fix the brackets and then see if it works.

Hello cereal,

I have fixed but keeps the same way...

Member Avatar for diafol

Show your updated code. Not convinced you've done it properly - you don't seem to be using an editor that checks syntax - so little errors like these scrape through.

EDIT:
I am using ATOM as my code editor.

UserController.php (I just edited on this on the brackets it was all what i fixed it the rest is like above)

    <?php
        class UserController extends \Phalcon\Mvc\Controller
        {
            protected function _getTranslation()
          {
            //Ask browser what is the best language
            $language = $this->request->getBestLanguage();
            //Check if we have a translation file for that lang
            if (file_exists("app/messages/".$language.".php")) {
               require "app/messages/".$language.".php";
            } else {
               // fallback to some default
               require "app/messages/en-US.php";
            }
            //Return a translation object
            return new \Phalcon\Translate\Adapter\NativeArray(array(
               "content" => $messages
            ));

            }
            public function indexAction()
            {
                $this->view->setVar("t", $this->_getTranslation());
            }
        }
    ?>
Member Avatar for diafol

That looks fine to me Nunix. The reason I asked about editor was that the original code (class) was missing a closing brace, which would be highlighted by most PHP editors. I'm not familiar with phalcon, but your variable is set for "t", so I'd assume the view code would be:

t['Do-you-shop-a-lot'] 

if $t is an array or more likely if an object:

t->content['Do-you-shop-a-lot']

Really don't know how the \Phalcon\Translate\Adapter\NativeArray(array("content" => $messages)) looks under the hood.

Well the \Phalcon\Translate\Adapter\NativeArray(array("content" => $messages)) could be like this:

<?php 

        // before the class
        use \Phalcon\Translate\Adapter\NativeArray;

        class UserController.php extends \Phalcon\Mvc\Controller {
            [...] //text in other reply above
            return new NativeArray(array("content" => $messages));
        }

and where it says return new it would be return new NativeArray(array("content" => $messages));

I think it is calling a template in Phalcon.
And the "content" it is the name of that calls all the contents of volt in /views/index.volt, where you have the menu and footer and after the menu we put it like this in volt {{ content() }} and it's already defined itself on volt template so that will recognize the content immediately.

I just went to the phalcon documentation and saw in there: https://docs.phalconphp.com/pt/2.0.0/reference/translate.html

Atleast I know that a lot of people use like that, what I don't know is if I need some special code to using inside volt or not.

Member Avatar for diafol

Well it looks like you may have got the pattern wrong:

<blockquote>{{  t_['blockquote']  }}</blockquote>

Could be:

<blockquote>{{  t->_('blockquote')  }}</blockquote>

I tried that but doesn't recognize "->" because of the volt template...

Member Avatar for diafol

Maybe

{{t._("blockquote")}}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.