0
Hey, guys, all right?
I have a problem to identify the page with the language at the same time. Just pulling the index with the languages and the other pages not.
This is the url expression: main.php
$urlpatterns = array(
'/' => 'index.php',
'/(?P<lang>\S+)' => 'index.php',
'/(?P<lang>\S+)/quem-somos' => 'quem-somos.php',
'/(?P<lang>\S+)/contato' => 'contato.php'
);
And this is the configuration of php translator.
if (isset($_GET['lang'])) {
$lang = explode("/", $_GET['lang']);
if ($lang[0] == "br") { $lang[0] = "br"; require_once ('br.php'); }
if ($lang[0] == "en") { $lang[0] = "en"; require_once ('en.php'); }
if ($lang[0] == "es") { $lang[0] = "es"; require_once ('es.php'); }
} elseif (!isset($_GET['lang'])) {
require_once ('br.php');
}
The URL looks like this: meusite.com.br/br or meusite.com.br/br/
But only search the home page, when I search for meusite.com.br/br/who-we are or meusite.com.br/en/who-we are, do not seek.
Could someone help me?
If I format everything on php translator., expressions will be ignored in main.php?
Well, your expression for language is
(?P<lang>\S+)
, which is basically any string with one or more characters that are not blank spaces. The URL/en/quem-somos
is a sequence of more than one character that are not blank spaces, so the displayed file should beindex.php
?– Woss
@Andersoncarloswoss I get it. What should I take out of this expression of mine to work? To identify the en-separate of who-we are: en**/**who we are?
– Felipe M. Gonçalves
Indicating that
lang
must not possess/
at value, for example,(?P<lang>[^/]+)
. This will define "lang" as any sequence of one or more characters that are not the bar. You can edit the expression to ignore other characters too if desired.– Woss
When I use this form it ends up giving error here in my code in the line of preg_match():

function url_response($urlpatterns) {
 foreach ($urlpatterns as $pcre => $app) {
 if(preg_match("@^{$pcre}$@", REQUEST_URI, $_GET)) {
 include(APPLICATION_DIR.'/'.$app);
 exit();
 } else {
 $erro = true;
 }
 }
 if(isset($erro) && $erro == true){
 include("app/404.php");
 }
 return;
}

– Felipe M. Gonçalves
What mistake would that be?
– Woss
It worked I ended up taking a parentheses in my edition. It worked as I expected. Thanks for the help!!!!!!
– Felipe M. Gonçalves