Skip to content

Commit

Permalink
Help improvements
Browse files Browse the repository at this point in the history
Document DONTTRANSLATE macro, reorg help sections
  • Loading branch information
Blake-Madden committed Sep 26, 2024
1 parent a20ca33 commit 72f3ee5
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 46 deletions.
61 changes: 35 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,41 @@ i18n-check

Internationalization & localization analysis system for C++ code, *gettext* catalogs, and Windows® RC files.

![](main-window.png)

`i18n-check` is a command-line utility and graphical interface that scans source and resource files and checks for
`i18n-check` is a command-line utility and graphical interface that scans source and resource files to check for
various i18n and l10n issues. Additionally, the GUI version provides pseudo-translation support for
*gettext* catalogs (\*.po files).

## Checks
## File Support

`i18n-check` supports static analysis for the following:

- C code
- C++ code ('98 and modern C++)
- Windows resource files (\*.rc)

Static analysis and pseudo-translation are also for:

- GNU *gettext* [@gettext] translation files (\*.po)

Additionally, it offers specialized support for the following frameworks:

- wxWidgets
- Qt
- KDE
- GTK+
- Win32
- MFC

¹ Strings are considered translatable if inside of [gettext](https://www.gnu.org/software/gettext/),
[wxWidgets](https://www.wxwidgets.org), [Qt](https://www.qt.io), or
[KDE](https://develop.kde.org/docs/plasma/widget/translations-i18n) (ki18n) i18n functions.
This includes functions and macros such as `gettext()`, `_()`, `tr()`, `translate()`,
`QT_TR_NOOP()`, `wxTRANSLATE()`, `i18n()`, etc.<br />
² Variables are determined to be ID variables if they are integral types with the whole word "ID" in their name.

Refer [here](Example.md) for example usage.

## Static Analysis

![](options-dialog-source.png)

Expand Down Expand Up @@ -73,27 +101,6 @@ When pseudo-translating, a copy of all *gettext* \*.po and \*.pot files will be
with mutations of the respective source strings. These files (which will have a "pseudo_" prefix) can then be compiled into \*.mo files and
loaded by your application for integration testing.

## File Support

`i18n-check` will work with C, modern C++, and '98/'03 C++ code, GNU *gettext* translation files (\*.po), and Windows&reg; resource files (\*.rc).
In particular, it offers specialized support for the following frameworks:

- wxWidgets
- Qt
- KDE
- GTK
- Win32
- MFC

¹ Strings are considered translatable if inside of [gettext](https://www.gnu.org/software/gettext/),
[wxWidgets](https://www.wxwidgets.org), [Qt](https://www.qt.io), or
[KDE](https://develop.kde.org/docs/plasma/widget/translations-i18n) (ki18n) i18n functions.
This includes functions and macros such as `gettext()`, `_()`, `tr()`, `translate()`,
`QT_TR_NOOP()`, `wxTRANSLATE()`, `i18n()`, etc.<br />
² Variables are determined to be ID variables if they are integral types with the whole word "ID" in their name.

Refer [here](Example.md) for example usage.

[![Linux Build](https://github.com/Blake-Madden/i18n-check/actions/workflows/linux-build.yml/badge.svg)](https://github.com/Blake-Madden/i18n-check/actions/workflows/linux-build.yml)
[![macOS build](https://github.com/Blake-Madden/i18n-check/actions/workflows/macOS%20build.yml/badge.svg)](https://github.com/Blake-Madden/i18n-check/actions/workflows/macOS%20build.yml)
[![Windows build](https://github.com/Blake-Madden/i18n-check/actions/workflows/msw-build.yml/badge.svg)](https://github.com/Blake-Madden/i18n-check/actions/workflows/msw-build.yml)
Expand Down Expand Up @@ -238,7 +245,9 @@ After building, "i18n-check" will be available in the "bin" folder.

# Building (GUI)

[wxWidgets](https://github.com/wxWidgets/wxWidgets) 3.2 or higher is required for building the graphical user interface version for `i18n-check`.
![](main-window.png)

[wxWidgets](https://github.com/wxWidgets/wxWidgets) 3.2 or higher is required for building the graphical user interface version `i18n-gui`.

Download [wxWidgets](https://github.com/wxWidgets/wxWidgets), placing it at the same folder level as `i18n-check`.
After building wxWidgets, `i18n-gui` can be configured and built with *Cmake*.
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ format:
keep-tex: true
citation-package: biblatex
cite-method: biblatex
lot: true
lot: false
code-block-bg: false
2 changes: 1 addition & 1 deletion docs/manual/building.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ After building, "i18n-check" will be available in the "bin" folder.

## GUI Version

[wxWidgets](https://github.com/wxWidgets/wxWidgets) 3.2 or higher is required for building the graphical user interface version for `i18n-check`.
[wxWidgets](https://github.com/wxWidgets/wxWidgets) 3.2 or higher is required for building the graphical user interface version `i18n-gui`.

Download [wxWidgets](https://github.com/wxWidgets/wxWidgets), placing it at the same folder level as `i18n-check`.
After building wxWidgets, `i18n-gui` can be configured and built with *Cmake*.
Expand Down
13 changes: 7 additions & 6 deletions docs/manual/command-line/samples.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ $ i18n-check ../samples -o results.txt

This will produce a "results.txt" file in the "bin" folder which contains tabular results. This file will contain warnings such as:

The `suspectL10NString` warning is because there is a string "GreaterThanOrEqualTo" that is inside of a `_()` macro, making it available for translation. This does not appear to be something appropriate for translation, hence the warning.
- `suspectL10NString`: indicates that the string "*GreaterThanOrEqualTo*" is inside of a `_()` macro, making it available for translation.
This does not appear to be something appropriate for translation; hence the warning.

The `suspectL10NUsage` warning is because the string "Invalid dataset passed to column filter." is being used in a call to `wxASSERT_MSG()`, which is a debug assert function.
- `suspectL10NUsage`: indicates that the string "*Invalid dataset passed to column filter.*" is being used in a call to `wxASSERT_MSG()`, which is a debug assert function.
Asserts normally should not appear in production releases and shouldn't be seen by end users; therefore, they should not be translated.

The `notL10NAvailable` warning is indicating that the string "\'%s\': string value not found for \'%s\' column filter." is not wrapped in a `_()` macro and not available for localization.
- `notL10NAvailable`: indicates that the string "*\'%s\': string value not found for \'%s\' column filter.*" is not wrapped in a `_()` macro and not available for localization.

The `deprecatedMacro` warning is indicating that the text-wrapping macro `wxT()` should be removed.
- `deprecatedMacro`: indicates that the text-wrapping macro `wxT()` should be removed.

The `nonUTF8File` warning is indicating that the file contains extended ASCII characters, but is not encoded as UTF-8.
- `nonUTF8File`: indicates that the file contains extended ASCII characters, but is not encoded as UTF-8.
It is generally recommended to encode files as UTF-8, making them portable between compilers and other tools.

The `unencodedExtASCII` warning is indicating that the string "\'%s\'--- column not found for filtering." contains a hard-coded extended ASCII character.
- `unencodedExtASCII`: indicates that the file contains hard-coded extended ASCII characters.
It is recommended that these characters be encoded in hexadecimal format to avoid character-encoding issues between compilers.

To look only for suspect strings that are exposed for translation and show the results in the console window:
Expand Down
Binary file added docs/manual/images/cover-thumnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 40 additions & 9 deletions docs/manual/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,34 @@ This book is licensed under the [Creative Commons Attribution-NonCommercial-NoDe

# Introduction

`i18n-check` is a command-line utility that scans a folder of a code and translation files and checks for the following issues:
`i18n-check` is a command-line utility and graphical interface that scans source and resource files to check for
various i18n and l10n issues. Additionally, the GUI version provides pseudo-translation support for
*gettext* catalogs (\*.po files).

## File Support

`i18n-check` supports static analysis for the following:

- C code
- C++ code ('98 and modern C++)
- Windows resource files (\*.rc)

Static analysis and pseudo-translation are also for:

- GNU *gettext* [@gettext] translation files (\*.po)

Additionally, it offers specialized support for the following frameworks:

- wxWidgets
- Qt
- KDE
- GTK+
- Win32
- MFC

## Static Analysis

The command line and GUI versions provide the following checks:

- Strings exposed for translation[^1] that probably should not be. This includes (but not limited to):
- Filenames
Expand Down Expand Up @@ -54,15 +81,19 @@ Code formatting issues can also be checked for, such as:
- Lines longer than 120 characters.
- Spaces missing between "//" and their comments.

`i18n-check` will work with C code, '98 and modern C++ code, GNU *gettext* [@gettext] translation files (\*.po), and Windows resource files (\*.rc).
In particular, it offers specialized support for the following frameworks:
## Pseudo-translation

- wxWidgets
- Qt
- KDE
- GTK
- Win32
- MFC
(available in the GUI version)

Pseudo-translation includes features such as:
- Multiple methods for character replacement (e.g., replacing characters with accented variations or upper casing them).
- Increasing the width of the translations. This is useful for ensuring that strings are not being truncated at runtime.
- Wrapping the translations in braces. This is useful for ensuring that strings are not being pieced together at runtime.
- Appending a unique ID to each translation. This is useful for finding where a translation is being loaded from.

When pseudo-translating, a copy of all *gettext* \*.po and \*.pot files will be created and have their translations filled
with mutations of the respective source strings. These files (which will have a "pseudo_" prefix) can then be compiled into \*.mo files and
loaded by your application for integration testing.

[^1]: Strings are considered translatable if inside of [gettext](https://www.gnu.org/software/gettext/),
[wxWidgets](https://www.wxwidgets.org), [Qt](https://www.qt.io), or
Expand Down
61 changes: 58 additions & 3 deletions docs/manual/suppression.qmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,73 @@
# Inline Suppression

## Code Blocks

Warnings can be suppressed for blocks of source code by placing `i18n-check-suppress-begin` and `i18n-check-suppress-end` comments around them.
For example:

``` {.cpp}
// i18n-check-suppress-begin
if (_debug && allocFailed)
AfxMessageBox("Allocation failed");
AfxMessageBox("Allocation failed!");
// i18n-check-suppress-end
```

This will prevent a warning from being emitted about "Allocation failed" not being available for localization.

::: {.notesection data-latex=""}
::: {.warningsection data-latex=""}
The comment style of the begin and end tags must match. For example, if using multi-line comments
(i.e., `/**/`), then both tags must be inside of `/**/` blocks.
:::
:::

## Individual Strings

To instruct the program that a particular string is not meant for localization, wrap it inside of a `_DT()` or `DONTTRANSLATE()` function call.
By doing this, the program will not warn about it not being available for localization. For example, both strings in the following will
be ignored:

``` {.cpp}
if (allocFailed)
MessageBox(DONTTRANSLATE("Allocation failed!"));
else
WriteMessage(_DT("No memory issues"));
```

You can either include the file "donttranslate.h" into your project to add these functions, or you can define your own:

``` {.cpp}
#define DONTTRANSLATE(x) (x)
#define _DT(x) (x)
```

{{< pagebreak >}}

If using the versions provided in "donttranslate.h," additional arguments can be included to explain why strings should not
be available for translation. For example:

``` {.cpp}
const std::string fileName = "C:\\data\\logreport.txt";
// "open " should not be translated, it's part of a command line
auto command = DONTTRANSLATE("open ") + fileName;
// expands to "open C:\\data\\logreport.txt"
// a more descriptive approach
auto command2 = DONTTRANSLATE("open ", DTExplanation::Command) + fileName;
// also expands to "open C:\\data\\logreport.txt"
// an even more descriptive approach
auto command3 = DONTTRANSLATE("open ",
DTExplanation::Command,
"This is part of a command line, "
"don't expose for translation!") +
fileName;
// also expands to "open C:\\data\\logreport.txt"
// a shorthand, _DT(), is also available
auto command = _DT("open ") + fileName;
```

::: {.notesection data-latex=""}
`_DT()` and `DONTTRANSLATE()` do not have any effect on the code and would normally be compiled out. Their purpose is only to inform `i18n-check`
that their arguments should not be translatable.
:::

0 comments on commit 72f3ee5

Please sign in to comment.