Skip to content

Commit

Permalink
l10n: switch localized format to macros instead of templatomicon
Browse files Browse the repository at this point in the history
  • Loading branch information
cthbleachbit committed Jun 7, 2024
1 parent a034718 commit 29c79cc
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 63 deletions.
54 changes: 54 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated from CLion C/C++ Code Style settings
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: false
AlignTrailingComments: false
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: false
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '^".*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentWidth: 4
InsertNewlineAtEOF: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
TabWidth: 4
UseTab: Always
...
122 changes: 59 additions & 63 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#ifdef _USE_GETTEXT

#include <libintl.h>
#include <fmt/format.h>
#include <libintl.h>

#ifndef _LOCALE_DIR
#define _LOCALE_DIR "/usr/local/share/locale/"
Expand All @@ -17,30 +17,24 @@
#define _TEXT_DOMAIN "Minemap"
#endif /* ifndef _TEXT_DOMAIN */

/*
* Give gettext an alias
*/
#define _(x) gettext (x)
#define _(x) gettext(x)

/**
* @brief Wrap fmt::format for use with translated string generated at runtime.
*
* @tparam T formatting arguments types
* @param fmt localized string
* @param args formatting arguments for this localized string
* @return formatted string
*/
template<typename ... T>
inline std::string localizedFormat(std::string_view fmt, T &&... args) {
return fmt::vformat(fmt, fmt::make_format_args(std::forward<T>(args)...));
}
#ifdef fmt::runtime
/* fmt::runtime() becomes available in fmt 9 and on - no need to do vformat wrestling */
#define localizedFormat(x, ...) fmt::format(fmt::runtime(_(x)), __VA_ARGS__)
#else
/* Without fmt::runtime(), formatting args need to be wrapped in make_format_args() then passed to vformat */
#define localizedFormat(x, ...) fmt::vformat(_(x), fmt::make_format_args(__VA_ARGS__))
#endif

#else /* ifdef _USE_GETTEXT */

/*
* If gettext is not available or disabled, make _() and localizedFormat() short circuits.
*/
#define _(x) x
#define localizedFormat fmt::format

#endif /* ifdef _USE_GETTEXT */

/**
Expand All @@ -61,7 +55,7 @@ inline void initializeLocale() {
#define INVALID_GAME_VER _("Invalid Minecraft Version Specifier")

#define MISSING_GAME_VER _("No game version or invalid version specified")
#define MISSING_IN_FILE _("No input file specified")
#define MISSING_IN_FILE _("No input file specified")
#define MISSING_OUT_FILE _("No output file specified")
#define MISSING_MARKER _("Missing marker type / operation")

Expand All @@ -79,55 +73,57 @@ inline void initializeLocale() {
#define BANNERS_MALFORMED _("Banners in this map is malformed")
#define POSITION_MALFORMED _("Position coordinates in this marker is malformed")
#define COLOR_MISMATCH _("BUG: No color match for pixel at ({}, {}). Please submit a bug report.")
#define COLOR_PARTIALLY_TRANSPARENT _("Warning: Had to render {} partially transparent pixels into fully transparent ones. Your output might look incorrect.")
#define COLOR_PARTIALLY_TRANSPARENT \
_("Warning: Had to render {} partially transparent pixels into fully transparent ones. Your output might look " \
"incorrect.")
#define COLOR_OUT_OF_RANGE _("Color code {} at offset {} is out of range!")

/* Usage Text */

#define MINEMAP_USAGE _( "Usage: minemap <options>\n" \
"\t-d, --dithering\n" \
"\t\tOptional, turn on Floyd-Steinberg dithering\n" \
"\t-i, --input INPUT\n" \
"\t\tRequired, image input\n" \
"\t--no-gz\n" \
"\t\tOptional, do not gzip generated NBT file (for human inspection)\n" \
"\t-o, --output FILE\n" \
"\t\tRequired, output file in NBT format\n" \
"\t-r, --replace\n" \
"\t\tOptional, replace map contents preserving markers if the output file already exists\n" \
"\t-e, --export FILE\n" \
"\t\tOptional, export the result of color reduction in png format\n" \
"\t-g, --game VER\n" \
"\t\tRequired, MINIMUM game version this map can be used in\n" \
"\t\tSelect from the following values: \n" \
)

#define PAMENIM_USAGE _( "Usage: pamenim <options>\n" \
"\t-i, --input INPUT\n" \
"\t\tRequired, nbt input\n" \
"\t--no-gz\n" \
"\t\tOptional, indicates that the input file is uncompressed\n" \
"\t-o, --output OUTPUT\n" \
"\t\tRequired, output picture, use '-' to write PNG to stdout\n" \
"\t-g, --game VER\n" \
"\t\tRequired, Minecraft game version this map is exported from\n" \
"\t\tSelect from the following values: \n" \
)

#define MINEMARKER_USAGE _( "Usage: minemarker <options> [operation]\n" \
"Available operations:\n" \
"\tedit\n" \
"\t\tLaunch a text editor to edit banners in this map item\n" \
"\tapply\n" \
"\t\tRead banner descriptions from stdin and apply them to the map\n" \
"\tdump\n" \
"\t\tPrint banners in this map to stdout for manual editing\n" \
"Available options:\n" \
"\t-i, --input INPUT\n" \
"\t\tRequired, nbt map file to modify\n" \
"\t--no-gz\n" \
"\t\tOptional, indicates that the input file is uncompressed\n" \
)
#define MINEMAP_USAGE \
_("Usage: minemap <options>\n" \
"\t-d, --dithering\n" \
"\t\tOptional, turn on Floyd-Steinberg dithering\n" \
"\t-i, --input INPUT\n" \
"\t\tRequired, image input\n" \
"\t--no-gz\n" \
"\t\tOptional, do not gzip generated NBT file (for human inspection)\n" \
"\t-o, --output FILE\n" \
"\t\tRequired, output file in NBT format\n" \
"\t-r, --replace\n" \
"\t\tOptional, replace map contents preserving markers if the output file already exists\n" \
"\t-e, --export FILE\n" \
"\t\tOptional, export the result of color reduction in png format\n" \
"\t-g, --game VER\n" \
"\t\tRequired, MINIMUM game version this map can be used in\n" \
"\t\tSelect from the following values: \n")

#define PAMENIM_USAGE \
_("Usage: pamenim <options>\n" \
"\t-i, --input INPUT\n" \
"\t\tRequired, nbt input\n" \
"\t--no-gz\n" \
"\t\tOptional, indicates that the input file is uncompressed\n" \
"\t-o, --output OUTPUT\n" \
"\t\tRequired, output picture, use '-' to write PNG to stdout\n" \
"\t-g, --game VER\n" \
"\t\tRequired, Minecraft game version this map is exported from\n" \
"\t\tSelect from the following values: \n")

#define MINEMARKER_USAGE \
_("Usage: minemarker <options> [operation]\n" \
"Available operations:\n" \
"\tedit\n" \
"\t\tLaunch a text editor to edit banners in this map item\n" \
"\tapply\n" \
"\t\tRead banner descriptions from stdin and apply them to the map\n" \
"\tdump\n" \
"\t\tPrint banners in this map to stdout for manual editing\n" \
"Available options:\n" \
"\t-i, --input INPUT\n" \
"\t\tRequired, nbt map file to modify\n" \
"\t--no-gz\n" \
"\t\tOptional, indicates that the input file is uncompressed\n")

#define VERSION_RANGE _("\t\t\t{:>8} for game version from {} to {}\n")
#define VERSION_OLDER_UNSUPPORTED _("\t\tOlder versions are not supported.\n\n")
Expand Down

0 comments on commit 29c79cc

Please sign in to comment.