View Single Post
Old 07-23-2022, 11:24 AM   #8
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,457
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Wiggo View Post
Code:
program:
	icon1 = if $$languages == 'englisch' then 'uk.png' else '' fi;
	icon2 = if $$#read == 'true' then 'ok.png' else  '' fi;
	icon3 = if $$#redl == 'true' then 'auto-reload.png' else '' fi;
	icon4 = if $$#toread == 'true' then 'reference.png' else '' fi;
	icon1 & ':' & icon2 & ':' & icon3 & ':' & icon4
I don't get language to work and not a 3x condition for #read (true, false, not defined).
I think you want something like this.
Code:
program:
	def add_icon(icon, val):
		if icon == '' then icon = val else icon = icon & ':' & val fi;
		return icon
	fed;

	icon = '';
	if $languages == 'eng' then icon = add_icon(icon, 'uk.png') fi;
	icon = add_icon(
		icon, 
		switch(
			$$#read,
			'true', 'ok.png',
			'false', 'false_icon.png',
			'unset_icon.png'));
	if $$#redl == 'true' then add_icon(icon, 'auto-reload.png') fi;
	if $$#toread == 'true' then add_icon(icon, 'reference.png') fi;
	return icon
Rationale:
  • The language code check must look for the three-letter value as shown in this web page, not the full language name. If you want to indicate other languages then use a switch() as explained below.
  • Using $$ (raw_field()) of a tristate boolean returns one of three values: "true", "false", and "none". These are not translated.
  • The switch function is a good substitute for a sequence of if/then/elif/else that check string matches.
  • It is best for performance not to have empty values separated by colons. The add_icon function takes care of that by adding the colon only if the icon string already has a value.
chaley is offline   Reply With Quote