Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6644997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:13:58+00:00 2026-05-26T00:13:58+00:00

so im making homepage with three languages. I am using switch method, here is

  • 0

so im making homepage with three languages.
I am using switch method, here is code –

  public function languages()
{
if (isset($_GET['lang']) && $_GET['lang'] != '')
{
  $_SESSION['lang'] = $_GET['lang'];
}
else
{
  $_SESSION['lang'] = 'en_EN';
}
switch($_SESSION['lang'])
{
  case 'en_EN': require_once('language/lang.eng.php');break;
  case 'lv_LV': require_once('language/lang.lv.php');break;
  case 'ru_RU': require_once('language/lang.ru.php');break;
  default: require_once('language/lang.eng.php');
}
}

public function translate($txt)
{
  global $text;
  return $text[$txt];
}

and it should display in index.php file like this –

<?php $index->translate('search'); ?>

but the problem is that it shows no errors, no notices, no warnings and no translated or default text.
I included function languages() , maybe you can help me with this problem?

EDIT:
im calling $language at start of index.php file – <?php require_once('class.index.php'); $index = new index; $index->languages(); ?> and $text is defined in lang.eng.php; lang.lv.php and lang.ru.php file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:13:59+00:00Added an answer on May 26, 2026 at 12:13 am

    Since you’re using a class, I think it’s better to use properties instead of globals, it will be easier in future mantainance. Create a class variable holding $text and use that

    class Index {
    
      var $text;
    
      public function languages()
      {
        require(".....");
    
        $this->text = $text;
      }
    
      public function translate($txt)
      {
        if(isset($this->text[$txt]))
        {
          return $this->text[$txt];
        }
        else
        {
         return "no translation";
        }
      }
    
    }
    
    $index = new Index;
    $index->languages();
    echo $index->translate('search'); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When making changes using SubmitChanges() , LINQ sometimes dies with a ChangeConflictException exception with
I am currently making a homepage where logged in users can write comments. The
I am making a homepage at the moment and I have made an edge
I'm making a website with a simple form on the homepage. When the user
Im making my own application by using GWT framework. I say that many Class
making a thumbnail from video using the picker is straight forward. However, when I
I am making a XML-driven homepage. A menu structure is generated and when clicking
I am making an html/javascript browser homepage, that could be downloaded to any computer
I tried copying the exact same code from the FullCalendar Homepage . So I
I am making an application for online blog I am using JqueryMobile features to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.