// // aegis - project change supervisor // Copyright (C) 2012-2014 Peter Miller // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, or (at // your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program. If not, see . // #include #include #include #include #include #include #include process_item_i18n::~process_item_i18n() { } process_item_i18n::process_item_i18n(target &a_tgt) : process_item(a_tgt, &target::process_item_i18n) { } process_item_i18n::pointer process_item_i18n::create(target &a_tgt) { return pointer(new process_item_i18n(a_tgt)); } bool process_item_i18n::condition(const nstring &filename) { nstring_list components; components.split(filename, "/"); // from this: "po/locale.po" // or this: "po/projectname.locale.po" if ( components.size() == 2 && components[0] == "po" && components[1].ends_with(".po") ) return true; // fom this: "lib/en/LC_MESSAGES/aegis.po" return ( components.size() >= 3 && components[components.size() - 2].upcase() == "LC_MESSAGES" && components[components.size() - 1].ends_with(".po") ); } void process_item_i18n::preprocess(const nstring &filename) { if (filename.ends_with("/common.po")) { // Do nothing directly, // it will be used indirectly by other rules. return; } assert(condition(filename)); nstring mo = filename.trim_extension() + ".mo"; data.remember_all_i18n(mo); // // We have to calculate what the installed destination files // look like. It is very similar to the .mo file we just built, // but has to arrive in the correct place, using just the right // abount of the .mo file's path. // // something like "/usr/share/locale/ru/LC_MESSAGES/aegis.mo" // NLSDIR ^^^^^^^^^^^^^^^^^ // ${datarootdir} ^^^^^^^^^^ // // The logic here MUST be the same as aemakegen/target/make/makefile.cc // nstring_list src_parts; src_parts.split(filename, "/"); nstring locale_name; nstring base; // e.g.: po/fubar.po // NOTE: this test mut be same as // aemakegen/target/make/makefile.cc // target_make_makefile::process_item_i18n if ( src_parts.size() == 2 && src_parts[0] == "po" && src_parts.back().ends_with(".po") ) { // e.g.: po/ru.po // e.g.: po/projetname.ru.po nstring_list src_dot_parts; src_dot_parts.split(src_parts[1], "."); assert(src_dot_parts.back() == "po"); if (src_dot_parts.size() == 3) { locale_name = src_dot_parts[1]; base = src_dot_parts[0]; } else if (src_dot_parts.size() == 2) { locale_name = src_dot_parts[0]; base = get_project_name(); } if (!is_a_locale_name(locale_name)) { fatal_raw ( "%s: does not appear to include a locale name as the " "last path component (%s)", filename.c_str(), src_parts.back().c_str() ); } } else { // e.g.: datadir/ru/LC_MESSAGES/aegis.po while (src_parts.size() > 3) src_parts.pop_front(); // e.g.: ru/LC_MESSAGES/aegis.po locale_name = src_parts[0]; if (!is_a_locale_name(locale_name)) { fatal_raw ( "%s: does not appear to include a locale name as the " "third-last path component (%s)", filename.c_str(), src_parts[0].c_str() ); } base = src_parts[2].trim_extension(); } if (!data.have_nlsdir()) { fatal_raw ( "%s: the configure.ac file does not appear to contain a " "AC_SUBST(NLSDIR) defintion, and yet the project would " "appear to require it (NLSDIR=${datarootdir}/locale)", filename.c_str() ); } // // something like "/usr/share/locale/ru/LC_MESSAGES/aegis.mo" // NLSDIR ^^^^^^^^^^^^^^^^^ // ${datarootdir} ^^^^^^^^^^ // nstring dst = "$(NLSDIR)/" + locale_name + "/LC_MESSAGES/" + base + ".mo"; data.remember_install_i18n(dst); data.set_install_data_macro(); } // vim: set ts=8 sw=4 et :