Skip to content

Commit

Permalink
Error handling when Locale cannot be set.
Browse files Browse the repository at this point in the history
- Exception handling when the locale cannot be set (will not set locale and sort by the default locale)
- Added locale based sorting information to readme
  • Loading branch information
smrky1 committed Feb 11, 2024
1 parent e8d494e commit 4bacc78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Again, to generate tabs go to the **[Online Generator](http://domdiv.bgtools.net

If you do need to install the package locally (the script provides a lot more options than the web-based generator), a simple `pip install domdiv` should suffice, providing a command by the name of `dominion_dividers`. However, see the note under Prerequisites->Fonts below as the default install will fall back on a font that doesn't match the cards (though most people don't notice). Run `dominion_dividers <outfile>` to get a pdf of all dividers with the default options, or run `dominion_dividers --help` to see the (extensive) list of options.

Linux only: to ensure the dividers are generated sorted by correct alphabetical order in your selected language, you have to generate the appropriate locale on your system. Run `apt-get -y install locales`, followed by `locale-gen xx_XX`, where `xx_XX` is one of the following: `en_US`, `de_DE`, `fr_FR`, `en_US`, `es_ES`, `it_IT`, `nl_NL,` `cs_CZ` (according to your selected language). In Windows OS this step is not necessary.


## Documentation

The script has an extensive set of options that are relatively well documented via `dominion_dividers --help`. Some are hard to describe unless you see output samples, so we recommend running the script with various options to see which configuration you like. The help output is replicated [here](https://github.com/sumpfork/dominiontabs/wiki/Documentation-%28Script-Options%29) for reference.
Expand Down
20 changes: 16 additions & 4 deletions src/domdiv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,10 +1500,22 @@ def __init__(self, order, lang, baseCards):
self.baseCards.append(baseCards[tag])

# Set the locale to the selected language. Necessary for correct sorting using accented characters
if os.name == "nt":
locale.setlocale(locale.LC_COLLATE, lang)
elif os.name == "posix":
locale.setlocale(locale.LC_COLLATE, (lang, ""))
# "nt" = Windows
# "posix" = Linux / macOS
try:
if os.name == "nt":
locale.setlocale(locale.LC_COLLATE, lang)
elif os.name == "posix":
locale.setlocale(locale.LC_COLLATE, (lang, ""))
except locale.Error:
print(
"** Warning: Unable to set correct locale: "
+ lang
+ "(will use default locale for cards sorting). "
"If running Unix OS, make sure to run "
"locale-gen for the desired language!\n",
file=sys.stderr,
)

# When sorting cards, want to always put "base" cards after all
# kingdom cards, and order the base cards in a particular order
Expand Down

0 comments on commit 4bacc78

Please sign in to comment.