From d8869b8b341c1e048ba146cf3208fc3a5e5fbacc Mon Sep 17 00:00:00 2001 From: zvon Date: Wed, 1 Apr 2020 14:34:56 +0200 Subject: [PATCH] Linux localization: check if locale exists in /usr/share/locale and bindtextdomain accordingly --- gui.cpp | 16 ++++++++++++---- main.cpp | 18 +++++++++++++++--- mainwindow.cpp | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gui.cpp b/gui.cpp index 40ecab4..c1e68b7 100644 --- a/gui.cpp +++ b/gui.cpp @@ -5,6 +5,7 @@ #include #include +#include "filesystem.hpp" #include "mainwindow.hpp" #include "resources_linux.h" #include "tv_rename.hpp" @@ -18,10 +19,17 @@ int main( int argc, char **argv ) { if ( setlocale( LC_ALL, "" ) == NULL ) error( 1, errno, _( INVALID_LOCALE ).c_str() ); - if ( bindtextdomain( DOMAIN, "./locale" ) == NULL ) - error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); - if ( textdomain( DOMAIN ) == NULL ) - error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + if ( FSLib::exists( "/usr/share/locale/en_US/LC_MESSAGES/tv_rename.mo" ) ) { + if ( bindtextdomain( DOMAIN, "/usr/share/locale" ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + if ( textdomain( DOMAIN ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + } else { + if ( bindtextdomain( DOMAIN, "./locale" ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + if ( textdomain( DOMAIN ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + } authenticate( API_KEY ); diff --git a/main.cpp b/main.cpp index ab3bdbf..88be40c 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,8 @@ using string = std::wstring; #else #include "resources_linux.h" +#include +#include #include using char_t = char; @@ -255,9 +257,19 @@ int main // set console to unicode _setmode( _fileno( stdout ), _O_U16TEXT ); #else - setlocale( LC_ALL, "" ); - bindtextdomain( DOMAIN, "./locale" ); - textdomain( DOMAIN ); + if ( setlocale( LC_ALL, "" ) == NULL ) + error( 1, errno, _( INVALID_LOCALE ).c_str() ); + if ( FSLib::exists( "/usr/share/locale/en_US/LC_MESSAGES/tv_rename.mo" ) ) { + if ( bindtextdomain( DOMAIN, "/usr/share/locale" ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + if ( textdomain( DOMAIN ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + } else { + if ( bindtextdomain( DOMAIN, "./locale" ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + if ( textdomain( DOMAIN ) == NULL ) + error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); + } #endif string show{}; std::set< int > seasons_num{}; diff --git a/mainwindow.cpp b/mainwindow.cpp index fec291c..a8c8460 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -250,7 +250,7 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr ) menu->append( *item ); // File menu - item->set_label( _( FILE ) ); + item->set_label( _( ID_FILE ) ); item->set_submenu( *submenu ); // Exit item for File menu