Linux localization: check if locale exists in /usr/share/locale and bindtextdomain accordingly

This commit is contained in:
zvon 2020-04-01 14:34:56 +02:00
parent 2e366f8b74
commit d8869b8b34
3 changed files with 28 additions and 8 deletions

View File

@ -5,6 +5,7 @@
#include <libintl.h> #include <libintl.h>
#include <locale.h> #include <locale.h>
#include "filesystem.hpp"
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "resources_linux.h" #include "resources_linux.h"
#include "tv_rename.hpp" #include "tv_rename.hpp"
@ -18,10 +19,17 @@ int main( int argc, char **argv ) {
if ( setlocale( LC_ALL, "" ) == NULL ) if ( setlocale( LC_ALL, "" ) == NULL )
error( 1, errno, _( INVALID_LOCALE ).c_str() ); 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 ) if ( bindtextdomain( DOMAIN, "./locale" ) == NULL )
error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() );
if ( textdomain( DOMAIN ) == NULL ) if ( textdomain( DOMAIN ) == NULL )
error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() ); error( 1, errno, _( MEM_ALLOC_FAILED ).c_str() );
}
authenticate( API_KEY ); authenticate( API_KEY );

View File

@ -19,6 +19,8 @@ using string = std::wstring;
#else #else
#include "resources_linux.h" #include "resources_linux.h"
#include <error.h>
#include <errno.h>
#include <getopt.h> #include <getopt.h>
using char_t = char; using char_t = char;
@ -255,9 +257,19 @@ int main
// set console to unicode // set console to unicode
_setmode( _fileno( stdout ), _O_U16TEXT ); _setmode( _fileno( stdout ), _O_U16TEXT );
#else #else
setlocale( LC_ALL, "" ); if ( setlocale( LC_ALL, "" ) == NULL )
bindtextdomain( DOMAIN, "./locale" ); error( 1, errno, _( INVALID_LOCALE ).c_str() );
textdomain( DOMAIN ); 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 #endif
string show{}; string show{};
std::set< int > seasons_num{}; std::set< int > seasons_num{};

View File

@ -250,7 +250,7 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr )
menu->append( *item ); menu->append( *item );
// File menu // File menu
item->set_label( _( FILE ) ); item->set_label( _( ID_FILE ) );
item->set_submenu( *submenu ); item->set_submenu( *submenu );
// Exit item for File menu // Exit item for File menu