diff options
| author | Matthias Melcher <github@matthiasm.com> | 2025-06-27 14:34:49 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2025-06-27 14:34:49 +0200 |
| commit | 3459e43ca830959d2b4ca71796a34ae7b21a819e (patch) | |
| tree | 0e4bee6696fea137b1f0eff93b4f04f369bfed6f /fluid/proj | |
| parent | 088d98389cdc4c0ed38d05e4a8e59fab88198515 (diff) | |
FLUID: Move i18n settings into its own class
Diffstat (limited to 'fluid/proj')
| -rw-r--r-- | fluid/proj/i18n.cxx | 93 | ||||
| -rw-r--r-- | fluid/proj/i18n.h | 88 |
2 files changed, 181 insertions, 0 deletions
diff --git a/fluid/proj/i18n.cxx b/fluid/proj/i18n.cxx new file mode 100644 index 000000000..a00dcf2f2 --- /dev/null +++ b/fluid/proj/i18n.cxx @@ -0,0 +1,93 @@ +// +// Fluid Project Internationalization code for the Fast Light Tool Kit (FLTK). +// +// Copyright 2025 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#include "proj/i18n.h" + +#include "io/Project_Reader.h" +#include "io/Project_Writer.h" + +using namespace fld; + +using namespace fld::proj; + + +/** + Reset all project setting to create a new empty project. + */ +void I18n::reset() { + type = fld::I18n_Type::NONE; + + gnu_include = "<libintl.h>"; + gnu_conditional = ""; + gnu_function = "gettext"; + gnu_static_function = "gettext_noop"; + + posix_include = "<nl_types.h>"; + posix_conditional = ""; + posix_file = ""; + posix_set = "1"; +} + +void I18n::read(io::Project_Reader &f, const char *key) { + if (!strcmp(key, "i18n_type")) { + type = static_cast<fld::I18n_Type>(atoi(f.read_word())); + } else if (!strcmp(key, "i18n_gnu_function")) { + gnu_function = f.read_word(); + } else if (!strcmp(key, "i18n_gnu_static_function")) { + gnu_static_function = f.read_word(); + } else if (!strcmp(key, "i18n_pos_file")) { + posix_file = f.read_word(); + } else if (!strcmp(key, "i18n_pos_set")) { + posix_set = f.read_word(); + } else if (!strcmp(key, "i18n_include")) { + if (type == fld::I18n_Type::GNU) { + gnu_include = f.read_word(); + } else if (type == fld::I18n_Type::POSIX) { + posix_include = f.read_word(); + } + } else if (!strcmp(key, "i18n_conditional")) { + if (type == fld::I18n_Type::GNU) { + gnu_conditional = f.read_word(); + } else if (type == fld::I18n_Type::POSIX) { + posix_conditional = f.read_word(); + } + } +} + +void I18n::write(io::Project_Writer &f) const { + if ((type != fld::I18n_Type::NONE)) { + f.write_string("\ni18n_type %d", static_cast<int>(type)); + switch (type) { + case fld::I18n_Type::NONE: + break; + case fld::I18n_Type::GNU : /* GNU gettext */ + f.write_string("\ni18n_include"); f.write_word(gnu_include.c_str()); + f.write_string("\ni18n_conditional"); f.write_word(gnu_conditional.c_str()); + f.write_string("\ni18n_gnu_function"); f.write_word(gnu_function.c_str()); + f.write_string("\ni18n_gnu_static_function"); f.write_word(gnu_static_function.c_str()); + break; + case fld::I18n_Type::POSIX : /* POSIX catgets */ + f.write_string("\ni18n_include"); f.write_word(posix_include.c_str()); + f.write_string("\ni18n_conditional"); f.write_word(posix_conditional.c_str()); + if (!posix_file.empty()) { + f.write_string("\ni18n_pos_file"); + f.write_word(posix_file.c_str()); + } + f.write_string("\ni18n_pos_set"); f.write_word(posix_set.c_str()); + break; + } + } +}
\ No newline at end of file diff --git a/fluid/proj/i18n.h b/fluid/proj/i18n.h new file mode 100644 index 000000000..30e09efae --- /dev/null +++ b/fluid/proj/i18n.h @@ -0,0 +1,88 @@ +// +// Fluid Project Internationalization header for the Fast Light Tool Kit (FLTK). +// +// Copyright 2025 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#ifndef FLUID_PROJ_I18N_H +#define FLUID_PROJ_I18N_H + +#include <string> + +namespace fld { + +class Project; + +/** + Enumeration of available internationalization types. + */ +enum class I18n_Type { + NONE = 0, ///< No i18n, all strings are litearals + GNU, ///< GNU gettext internationalization + POSIX ///< Posix catgets internationalization +}; + +namespace io { +class Project_Reader; +class Project_Writer; +} + +namespace proj { + +/** + Data and settings for a FLUID project file. + */ +class I18n +{ +public: + Project &project_; + + /// One of the available internationalization types. + fld::I18n_Type type = I18n_Type::NONE; + /// Include file for GNU i18n, writes an #include statement into the source + /// file. This is usually `<libintl.h>` or `"gettext.h"` for GNU gettext. + std::string gnu_include = "<libintl.h>"; + // Optional name of a macro for conditional i18n compilation. + std::string gnu_conditional = ""; + /// For the gettext/intl.h options, this is the function that translates text + /// at runtime. This is usually "gettext" or "_". + std::string gnu_function = "gettext"; + /// For the gettext/intl.h options, this is the function that marks the translation + /// of text at initialisation time. This is usually "gettext_noop" or "N_". + std::string gnu_static_function = "gettext_noop"; + + /// Include file for Posix i18n, write a #include statement into the source + /// file. This is usually `<nl_types.h>` for Posix catgets. + std::string posix_include = "<nl_types.h>"; + // Optional name of a macro for conditional i18n compilation. + std::string posix_conditional = ""; + /// Name of the nl_catd database + std::string posix_file = ""; + /// Message set ID for the catalog. + std::string posix_set = "1"; + +public: // Methods + I18n(Project &p) : project_(p) {}; + ~I18n() = default; + void reset(); + void read(io::Project_Reader &f, const char *key); + void write(io::Project_Writer &f) const; +}; + +} // namespace proj + +} // namespace fld + +#endif // FLUID_PROJ_I18N_H + + |
