*

metacreo

  • **
  • 9 posts
get translation value in specific language
« on: August 22, 2024, 10:36:55 AM »
Hello,

Please tell me if there is a native function to get translation value in other of current locale.?
For example:
I get all lang codes array via $osLangs = osc_listLanguageCodes();
Next via helper I get current locale en_US value $curDescr =  __('Description', 'theme-or-plugin');

I need to get this values for other langs like $fr_FR_Descr = SOME_FUNCTION('Description', 'theme-or-plugin', 'fr_FR');

Thank you

Marked as best answer by metacreo on August 30, 2024, 07:22:26 AM
*

MB Themes

Re: get translation value in specific language
« Reply #1 on: August 27, 2024, 09:31:37 AM »
You would need to use gettext, but I do not think other locales are even loaded, it would slow down site for no reason.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

metacreo

  • **
  • 9 posts
Re: get translation value in specific language
« Reply #2 on: August 30, 2024, 07:49:17 AM »
Thank you. I just need to improve my auto-fill plugin for filling title and descr automatically.
Now I understand. Never worked with gettext before. Now it turns out to be a native PHP thing.
Well done osclass, keep it up, more PHP and less third-party frameworks.
No wonder your code simply flies even on relatively weak servers.
But there is always something to optimize.
For example, I noticed a very frequent call of the same functions instead of variables in template files.
Like osc_get_preference('reg_user_can_see_phone', 'osclass') called 3 times in item.php with call classes and access DB.
Thank you again

*

MB Themes

Re: get translation value in specific language
« Reply #3 on: September 02, 2024, 01:28:02 PM »
@metacreo
I think all preference values are loaded at once from database and does not cause additional database calls.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

metacreo

  • **
  • 9 posts
Re: get translation value in specific language
« Reply #4 on: September 05, 2024, 02:17:26 PM »
Yes, you are right.
I am just writing about little things. But when there are many of them, they can grow into a problem.
It is just a matter of habit, if there is an opportunity, you need to use it.

https://stackoverflow.com/questions/5717046/is-it-better-call-a-function-every-time-or-store-that-value-in-a-new-variable

Like here for example.
In comparison, the compilation time is negligible, but still the difference is twofold.

*

MB Themes

Re: get translation value in specific language
« Reply #5 on: September 05, 2024, 02:21:10 PM »
If you have one php file that will be called million times, it make sense.
If you have complex CMS, you will not do that as it's going to significantly overload code and provide 0 benefit for that.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

metacreo

  • **
  • 9 posts
Re: get translation value in specific language
« Reply #6 on: September 05, 2024, 03:02:18 PM »

measured on item.php :)

$start_time = microtime(true);
//$xVar = osc_get_preference('reg_user_can_see_phone', 'osclass');

    } else if(osc_get_preference('reg_user_can_see_phone', 'osclass') == 1 ........
    //} else if($xVar == 1 ........

    if(osc_get_preference('reg_user_can_see_phone', 'osclass') == 1 ........
    //if($xVar == 1 ........

    if(osc_get_preference('reg_user_can_see_phone', 'osclass') == 1 ........
    //if($xVar == 1 ........

$end_time = microtime(true);
$execution_time = ($end_time - $start_time);
echo 'Execution Time: ' . number_format($execution_time, 10) . ' Sec :)';

$xVar results:
Execution Time: 0.0000040531 Sec :)
Execution Time: 0.0000040531 Sec :)
Execution Time: 0.0000040531 Sec :)

Native function call:
Execution Time: 0.0000050068 Sec :)
Execution Time: 0.0000050068 Sec :)
Execution Time: 0.0000050068 Sec :)

I think I've had enough of this nonsense :) This topic can be deleted :))

*

MB Themes

Re: get translation value in specific language
« Reply #7 on: September 05, 2024, 03:18:37 PM »
That's the thing, it's not worth to overload code for 0.000001s  :-*
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots