-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how can i translate this date? #219
Comments
You could define separate rules using identifiers ending with language code, for example: $userLang = LanguageUtils::i()->getLanguageById(USER_LANGUAGE_ID);
$rulesText = Config::get("rules_" . $userLang->getLanguageCode()); Remember to import |
Any example of how it would be?, I have tried and the page gives me an error 500, unless I put it like this according to the languageutils:
to
anyway I can't get the desired result, what would the latte file look like? |
My bad - With that, you get a Here's an exmaple of <?php
use Wruczek\TSWebsite\Utils\TemplateUtils;
require_once __DIR__ . "/private/php/load.php";
$userLang = LanguageUtils::i()->getLanguageById(@$_SESSION["userlanguageid"]);
$rulesHtml = Config::get("rules_" . $userLang->getLanguageCode());
$data = [
"pagetitle" => __get("RULES_TITLE"),
"navActiveIndex" => 4,
"paneltitle" => '<i class="fas fa-book"></i>' . __get("RULES_PANEL_TITLE"),
"panelcontent" => $rulesHtml
];
TemplateUtils::i()->renderTemplate("simple-page", $data); |
I understood the php part, but I don't understand how the latte would show the language of that column. |
Template |
Yes, I don't think I explained myself well, everything works fine for me and it shows what column I want because I told it in the php through the id, but I wanted it to show the column based on the user's language, that is, if you have 3 or 4 columns that you want to show there depending on the language of the user, Imagine, I have 3 rows in the translations db, so instead of doing:
that shows only the row with that id, then make it show one of the 3 or 4 with the language according to the user, I do not know if I explained well, It will remain something like in your first example, something like this:
With this I want to get it to show that specific row but only show the user's language, but since they are different ids I don't know how to reframe it to have this result. |
So you simply want to get a translated phrase? You can see that the rules.php file already does that with: To get a translated phrase in PHP, use |
I have added a new column that has a timestamp to the translations db, basically and more directly, what I am looking for is to select two or 3 specific rows from the translations table for example langid 1, 2, 6 and show it according to the language that the user, if the user has language with id 2, show the timestam column of the langid 2 but only the timestam column not the whole row. |
I have no idea what you are trying to achieve, and there's probably a better way to do it. $db = DatabaseUtils::i()->getDb();
$translations = $db->select("translations", "*", [
"id" => [1, 2, 3], // get rows with IDs: 1, 2 ,3
"langid" => @$_SESSION["userlanguageid"],
]);
var_dump($translations); Object returned by |
I'm not explaining myself well, my apologies, what I want to achieve is to put in the rules latte the date of the last edition of the row, nothing more, but for that you have to select only the date column and the langid, and then display it according to the language of the user. |
To get a specific column only, you can replace $lastEdited = $db->get("translations", "timestamp", [
"identifier" => "RULES_TITLE",
"langid" => @$_SESSION["userlanguageid"],
]);
|
Thank you very much, that's what I was looking for, that the edited date appears with in the news, in my latte it was like this to show the date: PHP <?php
use Wruczek\TSWebsite\Utils\DatabaseUtils;
use Wruczek\TSWebsite\Utils\TemplateUtils;
require_once __DIR__ . "/private/php/load.php";
$db = DatabaseUtils::i()->getDb();
$edited = $db->get("translations", "edited", [
"identifier" => "REGLAS",
"langid" => @$_SESSION["userlanguageid"],
]);
$data = [
"pagetitle" => __get("RULES_TITLE"),
"paneltitle" => '<i class="fas fa-book"></i>' . __get("RULES_PANEL_TITLE"),
"edited" => $edited
];
TemplateUtils::i()->renderTemplate("reglas", $data); LATTE {strtotime($edited)|fuzzyDateAbbr} I think everything is fine, correct me if I'm wrong, anyway thank you very much !! |
Looks good, but I would first check in latte if the value is not null (it will be null if it was not found in DB). {if $edited !== null}
{strtotime($edited)|fuzzyDateAbbr}
{/if} I will close the issue :) |
I verified it this way, what is the difference between one and the other?
|
Your if statement is not valid, you first convert |
Ah okay, perfect, thanks again, everything is solved! |
How can I make it detect the user's language and display the row with its respective language id? For the moment I managed to display the row by selecting its id, but I would like it to display the row according to the defined language id.
The text was updated successfully, but these errors were encountered: