rllib  1
Functions | Variables
rlinifile.cpp File Reference
#include "rldefine.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <windows.h>
#include "rlinifile.h"
#include "rlcutil.h"
Include dependency graph for rlinifile.cpp:

Go to the source code of this file.

Functions

int rlSetTranslator (const char *language, const char *inifile)
 
static const char * fixquote (const char *text, char **mytext)
 
const char * rltranslate (const char *txt, char **mytext)
 
const char * rltranslate2 (const char *section, const char *txt, char **mytext)
 

Variables

static const char null_string [] = ""
 
static rlIniFiletrIniFile = NULL
 

Function Documentation

◆ fixquote()

static const char* fixquote ( const char *  text,
char **  mytext 
)
static

Definition at line 523 of file rlinifile.cpp.

524 {
525  if(strchr(text,'\\') == NULL) return text;
526  int len = strlen(text);
527  if(*mytext != NULL) delete [] *mytext;
528  *mytext = new char[len+1];
529  char *temp = *mytext;
530  int i2 = 0;
531  for(int i=0; i<len; i++)
532  {
533  if (text[i] == '\\' && text[i+1] == '=') { temp[i2] = '='; i++; }
534  else if(text[i] == '\\' && text[i+1] == 'n') { temp[i2] = '\n'; i++; }
535  else if(text[i] == '\\' && text[i+1] == 't') { temp[i2] = '\t'; i++; }
536  else if(text[i] == '\\' && text[i+1] == '\\') { temp[i2] = '\\'; i++; }
537  else { temp[i2] = text[i]; }
538  i2++;
539  }
540  temp[i2] = '\0';
541  //printf("fixquote(%s) return=%s\n", text, temp);
542  return temp;
543 }

◆ rlSetTranslator()

int rlSetTranslator ( const char *  language,
const char *  inifile 
)

Definition at line 512 of file rlinifile.cpp.

513 {
514  if(inifile != NULL)
515  {
516  if(trIniFile == NULL) trIniFile = new rlIniFile();
517  if(trIniFile->read(inifile) < 0) return -1;
518  }
519  trIniFile->setDefaultSection(language);
520  return 0;
521 }
static rlIniFile * trIniFile
Definition: rlinifile.cpp:510
int read(const char *filename)
Definition: rlinifile.cpp:116
void setDefaultSection(const char *section)
Definition: rlinifile.cpp:483

◆ rltranslate()

const char* rltranslate ( const char *  txt,
char **  mytext 
)

Definition at line 545 of file rlinifile.cpp.

546 {
547  if(trIniFile == NULL) return fixquote(txt,mytext); // use original language because translator is not initalized
548  const char *text = trIniFile->i18n(txt,"@"); // translate
549  if(strcmp(text,"@") == 0) return fixquote(txt,mytext); // use original language because there is no tranlation available
550  return fixquote(text,mytext); // return the translated text
551 }
static rlIniFile * trIniFile
Definition: rlinifile.cpp:510
const char * i18n(const char *tag, const char *default_text="")
Definition: rlinifile.cpp:493
static const char * fixquote(const char *text, char **mytext)
Definition: rlinifile.cpp:523

◆ rltranslate2()

const char* rltranslate2 ( const char *  section,
const char *  txt,
char **  mytext 
)

Definition at line 553 of file rlinifile.cpp.

554 {
555  //printf("rltranslate2(%s,%s) mytext=%s\n", section, txt, *mytext);
556  if(trIniFile == NULL) return fixquote(txt,mytext); // use original language because translator is not initalized
557  if(*section == '\0') return rltranslate(txt,mytext); // user did not call pvSelectLanguage()
558  const char *text = trIniFile->text(section,txt); // translate
559  if(text[0] == '\0') return fixquote(txt,mytext); // use original language because there is no tranlation available
560  return fixquote(text,mytext); // return the translated text
561 }
static rlIniFile * trIniFile
Definition: rlinifile.cpp:510
const char * text(const char *section, const char *name)
Definition: rlinifile.cpp:208
const char * rltranslate(const char *txt, char **mytext)
Definition: rlinifile.cpp:545
static const char * fixquote(const char *text, char **mytext)
Definition: rlinifile.cpp:523

Variable Documentation

◆ null_string

const char null_string[] = ""
static

Definition at line 27 of file rlinifile.cpp.

◆ trIniFile

rlIniFile* trIniFile = NULL
static

Definition at line 510 of file rlinifile.cpp.