-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2001 The LyX Team.
+/**
+ * \file src/gettext.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ====================================================== */
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
#include <config.h>
+#include "gettext.h"
+#include "messages.h"
+
+#include "support/environment.h"
+#include "support/lstrings.h"
+
+
+namespace lyx {
+
#ifdef HAVE_LOCALE_H
# include <locale.h>
#endif
-#include "LString.h"
+using support::setEnv;
-#ifdef ENABLE_NLS
+using std::string;
-# if HAVE_GETTEXT
-# include <libintl.h> // use the header already in the system *EK*
-# else
-# include "../intl/libintl.h"
-# endif
-char const * _(char const * str)
+namespace {
+
+static Messages & getLyXMessages()
{
- // I'd rather have an Assert on str, we should not allow
- // null pointers here. Lgb
- // Assert(str);
- if (str && str[0])
- return gettext(str);
- else
- return "";
+ static Messages lyx_messages;
+
+ return lyx_messages;
}
+} // anon namespace
-string const _(string const & str)
+
+docstring const _(string const & str)
{
- if (!str.empty()) {
- int const s = str.length();
- char * tmp = new char[s + 1];
- str.copy(tmp, s);
- tmp[s] = '\0';
- string const ret(gettext(tmp));
- delete [] tmp;
- return ret;
- } else {
- return string();
- }
+ return getLyXMessages().get(str);
}
+
+#ifdef ENABLE_NLS
+
void locale_init()
{
+ // Disable, as otherwise it overrides everything else incl. the doc language
+ setEnv("LANGUAGE", "");
# ifdef HAVE_LC_MESSAGES
setlocale(LC_MESSAGES, "");
# endif
setlocale(LC_NUMERIC, "C");
}
-void gettext_init(string const & localedir)
-{
- bindtextdomain(PACKAGE, localedir.c_str());
- textdomain(PACKAGE);
-}
-
-
#else // ENABLE_NLS
void locale_init()
setlocale(LC_NUMERIC, "C");
}
-void gettext_init(string const &)
+#endif
+
+
+docstring const translateIfPossible(docstring const & name)
{
+ if (support::isAscii(name))
+ // Probably from a standard configuration file, try to
+ // translate
+ return _(to_ascii(name));
+ else
+ // This must be from a user defined configuration file. We
+ // cannot translate this, since gettext accepts only ascii
+ // keys.
+ return name;
}
-#endif
+
+
+} // namespace lyx