Commit f6a5b9f7 authored by Claes Sjofors's avatar Claes Sjofors

Xtt, support for local language files for languages without any global language files

parent d344e130
...@@ -379,6 +379,8 @@ bool Lng::read() ...@@ -379,6 +379,8 @@ bool Lng::read()
char fname1[120]; char fname1[120];
char fname2[120]; char fname2[120];
pwr_tStatus sts; pwr_tStatus sts;
pwr_tStatus basests;
bool first_set = true;
if ( tree) if ( tree)
tree_DeleteTable( &sts, tree); tree_DeleteTable( &sts, tree);
...@@ -390,20 +392,21 @@ bool Lng::read() ...@@ -390,20 +392,21 @@ bool Lng::read()
strcpy( fname1, "$pwr_exe/en_us/xtt_lng.dat"); strcpy( fname1, "$pwr_exe/en_us/xtt_lng.dat");
strcpy( fname2, "$pwr_exe/%s/xtt_lng.dat"); strcpy( fname2, "$pwr_exe/%s/xtt_lng.dat");
if ( !read_files( fname1, fname2, true, &sts)) if ( read_files( fname1, fname2, true, &basests))
return false; first_set = false;
// Read project files // Read project files
strcpy( fname1, "$pwrp_exe/xtt_lng_en_us.dat"); strcpy( fname1, "$pwrp_exe/xtt_lng_en_us.dat");
strcpy( fname2, "$pwrp_exe/xtt_lng_%s.dat"); strcpy( fname2, "$pwrp_exe/xtt_lng_%s.dat");
if ( !read_files( fname1, fname2, false, &sts)) read_files( fname1, fname2, first_set, &sts);
if ( EVEN(sts) && EVEN(basests))
return false; return false;
return true; return true;
} }
bool Lng::read_files( char *fname1, char *fname2, bool global, pwr_tStatus *sts) bool Lng::read_files( char *fname1, char *fname2, bool first_set, pwr_tStatus *sts)
{ {
pwr_tFileName filename1, filename2; pwr_tFileName filename1, filename2;
...@@ -425,7 +428,7 @@ bool Lng::read_files( char *fname1, char *fname2, bool global, pwr_tStatus *sts) ...@@ -425,7 +428,7 @@ bool Lng::read_files( char *fname1, char *fname2, bool global, pwr_tStatus *sts)
} }
else if ( !fp1) { else if ( !fp1) {
*sts = LNG__FILE; *sts = LNG__FILE;
return global ? false : true; return false;
} }
ifstream fp2( filename2); ifstream fp2( filename2);
...@@ -442,16 +445,16 @@ bool Lng::read_files( char *fname1, char *fname2, bool global, pwr_tStatus *sts) ...@@ -442,16 +445,16 @@ bool Lng::read_files( char *fname1, char *fname2, bool global, pwr_tStatus *sts)
} }
else if ( !fp2) { else if ( !fp2) {
*sts = LNG__FILE; *sts = LNG__FILE;
return global ? false : true; return false;
} }
Row r1( fp1, filename1); Row r1( fp1, filename1);
Row r2( fp2, filename2); Row r2( fp2, filename2);
read_metadata( fp1, global, sts); read_metadata( fp1, first_set, sts);
read_metadata( fp2, global, sts); read_metadata( fp2, first_set, sts);
read_include( fp1, fp2, global, sts); read_include( fp1, fp2, false, sts);
bool hit = true; bool hit = true;
for (;;) { for (;;) {
...@@ -623,13 +626,24 @@ bool Lng::is_installed( lng_eLanguage language) ...@@ -623,13 +626,24 @@ bool Lng::is_installed( lng_eLanguage language)
dcli_search_file( fname, found_file, DCLI_DIR_SEARCH_END); dcli_search_file( fname, found_file, DCLI_DIR_SEARCH_END);
if ( ODD(sts)) return true; if ( ODD(sts)) return true;
// Try local translation file on $pwrp_exe also
strcpy( fname, "$pwrp_exe/xtt_lng_");
strcat( fname, lang_to_str( language));
strcat( fname, ".dat");
dcli_translate_filename( fname, fname);
sts = dcli_search_file( fname, found_file, DCLI_DIR_SEARCH_INIT);
dcli_search_file( fname, found_file, DCLI_DIR_SEARCH_END);
if ( ODD(sts)) return true;
return false; return false;
} }
void Lng::read_metadata( ifstream& fp2, bool global, pwr_tStatus *sts) void Lng::read_metadata( ifstream& fp2, bool first_set, pwr_tStatus *sts)
{ {
char line[40]; char line[200];
for (;;) { for (;;) {
if ( !fp2.getline( line, sizeof( line))) { if ( !fp2.getline( line, sizeof( line))) {
...@@ -641,20 +655,20 @@ void Lng::read_metadata( ifstream& fp2, bool global, pwr_tStatus *sts) ...@@ -641,20 +655,20 @@ void Lng::read_metadata( ifstream& fp2, bool global, pwr_tStatus *sts)
} }
if ( strncmp( line, "Coding:UTF-8", 12) == 0) { if ( strncmp( line, "Coding:UTF-8", 12) == 0) {
if ( global) if ( first_set)
translfile_coding = lng_eCoding_UTF_8; translfile_coding = lng_eCoding_UTF_8;
else if ( translfile_coding != lng_eCoding_UTF_8) else if ( translfile_coding != lng_eCoding_UTF_8)
*sts = LNG__DIFFCODING; *sts = LNG__DIFFCODING;
} }
else if ( strncmp( line, "Coding:ISO8859-1", 16) == 0) { else if ( strncmp( line, "Coding:ISO8859-1", 16) == 0) {
if ( global) if ( first_set)
translfile_coding = lng_eCoding_ISO8859_1; translfile_coding = lng_eCoding_ISO8859_1;
else if ( translfile_coding != lng_eCoding_ISO8859_1) else if ( translfile_coding != lng_eCoding_ISO8859_1)
*sts = LNG__DIFFCODING; *sts = LNG__DIFFCODING;
} }
else { else {
fp2.seekg( 0, ios::beg); fp2.seekg( 0, ios::beg);
if ( global) if ( first_set)
translfile_coding = lng_eCoding_ISO8859_1; translfile_coding = lng_eCoding_ISO8859_1;
else if ( translfile_coding != lng_eCoding_ISO8859_1) else if ( translfile_coding != lng_eCoding_ISO8859_1)
*sts = LNG__DIFFCODING; *sts = LNG__DIFFCODING;
...@@ -662,7 +676,7 @@ void Lng::read_metadata( ifstream& fp2, bool global, pwr_tStatus *sts) ...@@ -662,7 +676,7 @@ void Lng::read_metadata( ifstream& fp2, bool global, pwr_tStatus *sts)
*sts = LNG__SUCCESS; *sts = LNG__SUCCESS;
} }
void Lng::read_include( ifstream& fp1, ifstream& fp2, bool global, pwr_tStatus *sts) void Lng::read_include( ifstream& fp1, ifstream& fp2, bool first_set, pwr_tStatus *sts)
{ {
char line1[200]; char line1[200];
char line2[200]; char line2[200];
...@@ -697,7 +711,7 @@ void Lng::read_include( ifstream& fp1, ifstream& fp2, bool global, pwr_tStatus * ...@@ -697,7 +711,7 @@ void Lng::read_include( ifstream& fp1, ifstream& fp2, bool global, pwr_tStatus *
dcli_trim( fname1, &line1[8]); dcli_trim( fname1, &line1[8]);
dcli_trim( fname2, &line2[8]); dcli_trim( fname2, &line2[8]);
if ( !read_files( fname1, fname2, global, sts)) if ( !read_files( fname1, fname2, first_set, sts))
return; return;
} }
else { else {
......
...@@ -5599,6 +5599,22 @@ char *Graph::get_next_object_name( const char *prefix, const char *suffix) ...@@ -5599,6 +5599,22 @@ char *Graph::get_next_object_name( const char *prefix, const char *suffix)
return name; return name;
} }
void Graph::set_text_coding( lng_eCoding coding)
{
glow_eTextCoding c;
switch ( coding) {
case lng_eCoding_ISO8859_1:
c = glow_eTextCoding_ISO8859_1;
break;
case lng_eCoding_UTF_8:
c = glow_eTextCoding_UTF_8;
break;
}
grow_SetTextCoding( grow->base_ctx(), c);
}
static void graph_free_dyn( grow_tObject object) static void graph_free_dyn( grow_tObject object)
{ {
if ( grow_GetObjectType( object) == glow_eObjectType_GrowNode || if ( grow_GetObjectType( object) == glow_eObjectType_GrowNode ||
......
...@@ -44,6 +44,9 @@ ...@@ -44,6 +44,9 @@
#ifndef pwr_h #ifndef pwr_h
# include "pwr.h" # include "pwr.h"
#endif #endif
#ifndef co_lng_h
# include "co_lng.h"
#endif
#ifndef glow_h #ifndef glow_h
#include "glow.h" #include "glow.h"
#endif #endif
...@@ -1392,6 +1395,8 @@ class Graph { ...@@ -1392,6 +1395,8 @@ class Graph {
char *get_next_object_name( const char *prefix, const char *suffix); char *get_next_object_name( const char *prefix, const char *suffix);
void set_text_coding( lng_eCoding coding);
static int get_colortheme_colors( char *file, double **colors, int *size); static int get_colortheme_colors( char *file, double **colors, int *size);
//! Enable event logging //! Enable event logging
......
...@@ -4764,3 +4764,15 @@ int GrowCtx::check_object_name( char *name) ...@@ -4764,3 +4764,15 @@ int GrowCtx::check_object_name( char *name)
return GLOW__SUCCESS; return GLOW__SUCCESS;
} }
void GrowCtx::set_text_coding( glow_eTextCoding coding)
{
text_coding = coding;
// Set for subwindow
for ( int i = 0; i < a.a_size; i++) {
if ( a[i]->type() == glow_eObjectType_GrowWindow ||
a[i]->type() == glow_eObjectType_GrowFolder)
((GrowWindow *)a[i])->window_ctx->set_text_coding( coding);
}
}
...@@ -885,7 +885,7 @@ class GrowCtx : public GlowCtx { ...@@ -885,7 +885,7 @@ class GrowCtx : public GlowCtx {
double *ur_x, double *ur_y); double *ur_x, double *ur_y);
void pop( GlowArrayElem *element) { a.pop( element);} void pop( GlowArrayElem *element) { a.pop( element);}
void set_text_coding( glow_eTextCoding coding) { text_coding = coding;} void set_text_coding( glow_eTextCoding coding);
void set_edit_set_mode( glow_eEditSetMode mode) { edit_set_mode = mode;} void set_edit_set_mode( glow_eEditSetMode mode) { edit_set_mode = mode;}
int set_custom_color( glow_eDrawType color, double red, double green, double blue); int set_custom_color( glow_eDrawType color, double red, double green, double blue);
void reset_custom_colors(); void reset_custom_colors();
......
...@@ -254,6 +254,11 @@ void XttGe::event_exec( int type, void *event, unsigned int size) ...@@ -254,6 +254,11 @@ void XttGe::event_exec( int type, void *event, unsigned int size)
} }
} }
void XttGe::set_text_coding( lng_eCoding coding)
{
graph->set_text_coding( coding);
}
XttGe::XttGe( void *xg_parent_ctx, const char *xg_name, const char *xg_filename, XttGe::XttGe( void *xg_parent_ctx, const char *xg_name, const char *xg_filename,
int xg_scrollbar, int xg_menu, int xg_navigator, int xg_width, int xg_height, int xg_scrollbar, int xg_menu, int xg_navigator, int xg_width, int xg_height,
int x, int y, double scan_time, const char *object_name, int x, int y, double scan_time, const char *object_name,
......
...@@ -97,6 +97,7 @@ class XttGe { ...@@ -97,6 +97,7 @@ class XttGe {
void swap( int mode); void swap( int mode);
void update_color_theme( int color_theme); void update_color_theme( int color_theme);
void event_exec( int type, void *event, unsigned int size); void event_exec( int type, void *event, unsigned int size);
void set_text_coding( lng_eCoding coding);
static void graph_init_cb( void *client_data); static void graph_init_cb( void *client_data);
static int graph_close_cb( void *client_data); static int graph_close_cb( void *client_data);
......
...@@ -1039,6 +1039,7 @@ static int xnav_set_func( void *client_data, ...@@ -1039,6 +1039,7 @@ static int xnav_set_func( void *client_data,
else if ( cdh_NoCaseStrncmp( arg1_str, "LANGUAGE", strlen( arg1_str)) == 0) else if ( cdh_NoCaseStrncmp( arg1_str, "LANGUAGE", strlen( arg1_str)) == 0)
{ {
char language_str[80]; char language_str[80];
ApplListElem *elem;
// Command is "SET LANGUAGE" // Command is "SET LANGUAGE"
if ( EVEN( dcli_get_qualifier( "dcli_arg2", language_str, sizeof(language_str)))) { if ( EVEN( dcli_get_qualifier( "dcli_arg2", language_str, sizeof(language_str)))) {
...@@ -1047,6 +1048,12 @@ static int xnav_set_func( void *client_data, ...@@ -1047,6 +1048,12 @@ static int xnav_set_func( void *client_data,
} }
cdh_ToLower( language_str, language_str); cdh_ToLower( language_str, language_str);
Lng::set( language_str); Lng::set( language_str);
// Set new coding to all graphs
for ( elem = xnav->appl.root; elem; elem = elem->next) {
if ( elem->type == applist_eType_Graph)
((XttGe *)elem->ctx)->set_text_coding( Lng::translatefile_coding());
}
} }
else if ( cdh_NoCaseStrncmp( arg1_str, "NORATIO", strlen( arg1_str)) == 0) else if ( cdh_NoCaseStrncmp( arg1_str, "NORATIO", strlen( arg1_str)) == 0)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment