check that language variable exist

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

check that language variable exist

Post by emosbat »

how could check if a language variable exist or not (defined or not) from template?

Code: Select all

<!-- IF L_VARABLE_NAME -->
not works.

the goal is to set a default string if variable is not defined in a language. for example we have L_VARABLE_NAME in english, but not in dutch version so define a default text their and do not apear it like what it do (it will show "{ L_VARABLE_NAME }" instead).
User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm

Re: check that language variable exist

Post by Dugi »

emosbat wrote:how could check if a language variable exist or not (defined or not) from template?

Code: Select all

<!-- IF L_VARABLE_NAME -->
not works.

the goal is to set a default string if variable is not defined in a language. for example we have L_VARABLE_NAME in english, but not in dutch version so define a default text their and do not apear it like what it do (it will show "{ L_VARABLE_NAME }" instead).
You could do server side checking like:

Code: Select all

$template->assign_var('LANG_KEY_EXISTS', (isset($user->lang['MY_KEY'])) ? true : false);
And use it in your template like:

Code: Select all

<!-- IF LANG_KEY_EXISTS -->
or without using PHP at all:

Code: Select all

<!-- IF L_VARABLE_NAME eq '' -->
This language key is empty
<!-- ENDIF -->
I'm not sure about this non-PHP answer though.
PM me for custom extension pricing / My validated MODs / My MODs in development
User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: check that language variable exist

Post by emosbat »

I need a solution without php calls and second one not works because it will return variable name if not defined.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52111
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: check that language variable exist

Post by Brf »

How about something like

Code: Select all

<!-- IF L_VARIABLE_NAME eq ' VARIABLE NAME ' -->
Note the leading and trailing space inside the apostrophes.
User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: check that language variable exist

Post by emosbat »

Brf wrote:How about something like

Code: Select all

<!-- IF L_VARIABLE_NAME eq ' VARIABLE NAME ' -->
Note the leading and trailing space inside the apostrophes.
not working. return vaule contain { and } when variable is not defined { VARIABLE_NAME }.
but this not worked too!!

Code: Select all

<!-- IF L_VARIABLE_NAME eq ' { VARIABLE_NAME }' -->
:roll:
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52111
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: check that language variable exist

Post by Brf »

Take our the space before the "{"
User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: check that language variable exist

Post by emosbat »

no success :(

I think language variable do not work in condition (IF) ever. or should not be L_VARIABLE_NAME or VARIABLE_NAME.

here some test. no return 'OK' from all of these tests when variable not defined.
so it will not work ever in IF condition:

Code: Select all

<!-- IF L_VARIABLE_NAME eq ' L_VARIABLE_NAME ' -->OK<!-- ENDIF -->
<!-- IF L_VARIABLE_NAME eq '{ L_VARIABLE_NAME }' -->OK<!-- ENDIF -->
<!-- IF L_VARIABLE_NAME eq ' VARIABLE_NAME ' -->OK<!-- ENDIF -->
<!-- IF L_VARIABLE_NAME eq '{ VARIABLE_NAME }' -->OK<!-- ENDIF -->
<!-- IF VARIABLE_NAME eq ' VARIABLE_NAME ' -->OK<!-- ENDIF -->
<!-- IF VARIABLE_NAME eq '{ VARIABLE_NAME }' -->OK<!-- ENDIF -->
<!-- IF VARIABLE_NAME eq ' L_VARIABLE_NAME ' -->OK<!-- ENDIF -->
<!-- IF VARIABLE_NAME eq '{ L_VARIABLE_NAME }' -->OK<!-- ENDIF -->
:?
User avatar
Dugi
Registered User
Posts: 1386
Joined: Sun May 25, 2008 5:36 pm

Re: check that language variable exist

Post by Dugi »

A HTML only solution is kinda hard in this case. Why are you refusing to use PHP, any particular reason?
PM me for custom extension pricing / My validated MODs / My MODs in development
User avatar
emosbat
Registered User
Posts: 564
Joined: Sat Jan 28, 2012 1:25 pm

Re: check that language variable exist

Post by emosbat »

Dugi wrote:A HTML only solution is kinda hard in this case. Why are you refusing to use PHP, any particular reason?
I do not want to add extra definition for this in php side but also need a default message (it is a javascript message and it is not good to show { BLAHBLAH } thing for other languages when translation not exist).
/
update:
ok I find a javascript solution :mrgreen:

Code: Select all

<script type="text/javascript">
var my_text = '{L_VARIABLE_NAME}';

if(my_text=='{ VARIABLE_NAME }')
	my_text = 'alternative text';

// test
alert(my_text);
</script>
and then use my_text in html.
User avatar
AmigoJack
Registered User
Posts: 5774
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: check that language variable exist

Post by AmigoJack »

emosbat wrote:<!-- IF L_VARIABLE_NAME
This approach will never work, since language constants are only substituted when being found as {L_XXX}, since they're not expected to be handed over via assign_vars().
emosbat wrote:I find a javascript solution
...is also prone to fail if the text itself contains apostrophes or character sequences which will be interpreted by JS.

The overall approach is questionable, since you hardcode a specific language into the template file(s) of your style(s). To get what you want you're doomed to augment the template parser. An alternative approach (always loading English at first) would impact performance.

The best solution is to maintain the language files. Which is... obvious.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.
Locked

Return to “[3.0.x] MOD Writers Discussion”