[SOLVED] Class of language constants

12 years 10 months ago #147523 by kbotnen
[SOLVED] Class of language constants was created by kbotnen

I am facing a problem of getting hold of the constants that are defined in the language files.

I have come so far that I think I can get hold on them if I know which class they are belonging to.

The reason why I need them is because I need to do an reverse lookup on the language strings. I am doing a search in comprofiler, but I have saved the _UE_Country, _UE_Profession and so on strings into the database. When a user do a search he type "sweden banker" and not "_UE_Sweden _UE_Banker" , so I need a way to check if "sweden" is a value that has belongs to a constant, and if it does, replace "sweden" with the constants name (_UE_Sweden).


Post edited by: krileon, at: 2010/12/07 19:55

Please Log in to join the conversation.

12 years 10 months ago #147583 by krileon
Replied by krileon on topic Re:Class of language constants
You'll need to translate the string with getLangDefinition and check that against the string provided. CB API must be present in order to use getLangDefinition. Please see tutorials within signature in order to load CB API outside of CB if necessary. If code is in a CB Plugin just directly use the function.

Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

12 years 9 months ago #147952 by kbotnen
Replied by kbotnen on topic [SOLVED] Re:Class of language constants
I solved my initial problem thanks to krileons reply, a lot of searching around the net and irc.freenode channels #joomla and #php.

What I needed was to be able to check a incoming string for a certain word, check if it exist in some language translation defined constant, and if it did, replace it with the constants name. In short, replace a constant value with its constant name, backwards of what most people use constants for.

First I included the CB Api as described in one of krielons signature tutorials.

Then I imported the language:

Searching for a value, if found, return its key (the constants name):
$returnMe = "null";
$array = get_defined_constants(true);
foreach ($array as $subarray) {
foreach ($subarray as $key => $value) {
if ($value === $searchKey) {
$returnMe = $key;

This is just for reference if someone stumble upon this thread in the future :)

The reason I needed this is because of working on a module that enables mysql full-text search. So this searching function is just a tweak to deal with the fact that language translated fields get stored in the DB as _UE_Constantname, making them hard to find without knowing their names :)

Hopefully the module will be uploaded to the JED sometime this christmas. I will post a link to it here for reference if someone wants to see how it works.


Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.217 seconds

Facebook Twitter LinkedIn