Cheers
import unidecode
loadUnidecodeTable("lib/pure/unidecode/unidecode.dat")
assert unidecode("Äußerst") == "Ausserst"
It is in the stdlib.
Thank you. Worked as intented.
My final binary will be executed in a machine without the Nim source code. So, the loadUnidecodeTable("lib/pure/unidecode/unidecode.dat") won't worked.
Is there a way to do the loadUnidecodeTable at compiled time only?
Building up on @Araq's reply I would do:
import unidecode
import os
proc findNimStdLib*(): string =
## Tries to find a path to a valid "system.nim" file.
## Returns "" on failure.
try:
let nimexe = os.findExe("nim")
if nimexe.len == 0: return ""
result = nimexe.splitPath()[0] /../ "lib"
if not fileExists(result / "system.nim"):
when defined(unix):
result = nimexe.expandSymlink.splitPath()[0] /../ "lib"
if not fileExists(result / "system.nim"): return ""
except OSError, ValueError:
return ""
# Load the Unicode data file.
loadUnidecodeTable(findNimStdLib() / "pure/unidecode/unidecode.dat")
echo unidecode("Æneid") # AEneid
Ref: https://scripter.co/notes/nim/#unidecode
Related issue I just opened: https://github.com/nim-lang/Nim/issues/8767
## This module needs the data file "unidecode.dat" to work: You can either
## ship this file with your application and initialize this module with the
## `loadUnidecodeTable` proc or you can define the ``embedUnidecodeTable``
## symbol to embed the file as a resource into your application.
@Araq
Yes I read that doc-string, but the default of findNimStdLib() / "pure/unidecode/unidecode.dat" seems better.. Or is it a common practice for a user to put their own unidecode.dat in the same dir as their Nim source files?