Unicode 6.2: carrying the Turkish lira sign safely from data to display
Use the Turkish lira sign encoded in 2012 to test the boundaries between currency data, UTF-8 bytes, and fonts in a receipt example.
Archive retrospective · Topic year 2012
In this article
- A new receipt symbol does not change a balance
- Construct the value before picking a display format
- Measure the code point and the UTF-8 sequence separately
- Distinguish malformed bytes from missing font coverage
- Establish the source format before migrating old files
- Test the path through screen, export, and print
A new receipt symbol does not change a balance
In 2012 Unicode 6.2 included the Turkish lira sign at U+20BA. That let a receipt system carry an agreed character even while some deployed fonts and printers did not yet draw it. Consider a small synthetic receipt that stores 1,250 kuruş as its minor-unit amount and TRY as its currency. The amount stays the same if a browser draws a box instead of the sign. The data, the text generated for display, the transport encoding, and the font responsible for drawing it each have a different contract. The standard records the period change to the repertoire. It does not show the symbol working on every contemporary device. A team reprinting historical receipts needs to diagnose presentation without misclassifying it as a changed amount.
Construct the value before picking a display format
Keeping the amount in integer minor units prevents presentation such as 12,50 from turning into a storage convention. Our sample covers nonnegative sales. Refund signs, rounding rules, exchange rates, and currencies with other minor-unit scales require additional rules. Store a currency code with the amount and make any aggregation's currency filter explicit. UI formatting may choose a decimal mark, spacing, sign placement, or a plain code. The localized example uses a chosen Turkish display format, not a localization library promise. A report written with TL or a newer screen using the symbol can still represent the same currency. Exports that users will import again should include separate numeric and currency columns. This allows a visual formatting release without rewriting the numbers that reporting and reconciliation use.
Measure the code point and the UTF-8 sequence separately
U+20BA is the character identity. UTF-8 encodes it as E2 82 BA. A text inspector can show the first while a network or file inspector shows the second. The Python example builds the character using its number so it does not depend upon the interpreter knowing its Unicode name. A character count is not a byte count. Appending the symbol adds one code point to the text and three bytes to a UTF-8 payload. A receipt service can deliver the numeric fields in JSON and format them at the edge. JSON may represent the glyph with literal UTF-8 or an escape. An appropriate JSON decoder recovers the same character. Compare the original fields with the deserialized values before evaluating presentation.
import binascii
import json
record = {"currency": "TRY", "minor_units": 1250}
kind = record["currency"]
major, minor = divmod(record["minor_units"], 100)
sign = chr(0x20BA)
display = "{0},{1:02d} {2}".format(major, minor, sign)
assert display == "12,50 " + chr(0x20BA)
assert binascii.hexlify(sign.encode("utf-8")) == b"e282ba"
assert sign.encode("utf-8").decode("utf-8") == sign
payload = json.dumps(record, ensure_ascii=False).encode("utf-8")
assert json.loads(payload.decode("utf-8")) == record
assert kind == "TRY"
Distinguish malformed bytes from missing font coverage
Truncated UTF-8 can fail before there is any valid text. Decoding those bytes as Latin-1 may produce different characters without reporting an error. A separate problem occurs when the text contains U+20BA but the active font has no matching glyph. Its placeholder could resemble an encoding problem until the code point is checked. Copy text from the browser and inspect the character. Then check the PDF separately: the expected font may not be embedded and text extraction may not return the same symbol. A physical printer can select another font again. A readable screenshot is only one observation. Keep invalid input distinguishable from a correct stored receipt and a broken rendering. Retain original bytes for any failed ingestion that needs diagnosis.
event = b'12,50 \xe2\x82'
try:
event.decode("utf-8")
except UnicodeDecodeError:
pass
else:
raise AssertionError("incomplete character unexpectedly decoded")
clean = b'12,50 \xe2\x82\xba'
assert ord(clean.decode("utf-8")[-1]) == 0x20BA
wrong = clean.decode("latin-1")
assert wrong != clean.decode("utf-8")
Establish the source format before migrating old files
Files made before the change may not reliably disclose their encoding in their names. Compare a few rows with a known original and inspect the headers, Turkish letters, values, and symbol together. A limited terminal can display an explicitly documented TRY fallback. The underlying data can remain intact for later export. Before updating many archived records, test representative receipts and compare the numeric field, unit, and original identity. When the only change is presentational, the original fields should still be reusable without reconstructing amounts from formatted strings. Record the selected source encoding, parsing error counts, and sample identifiers. Appropriate diagnostics need not include every purchaser's full receipt. A read-only position before conversion also makes it possible to recover from an incorrect assumption.
Test the path through screen, export, and print
First compare the code point and expected UTF-8 bytes. Next round-trip the amount and currency. Exercise browser font fallback, a device without the preferred font, and a PDF export. When the browser is correct but the PDF shows a box, compare their font configuration directly. Add data cases such as zero, 99, and 100 kuruş so the formatting check catches a lost minor-unit digit. Try copying and reimporting text and printing it with a representative device. A screen reader may benefit from an explicit spoken currency label in the relevant flow. A fallback using TRY should keep the same monetary meaning. The useful engineering lesson is that calculation, encoding, and representation can be tested independently while keeping the receipt useful at each stage.
Reader discussion
Which data would you verify before applying this development in your field?
No comments yet. Be the first to contribute.
Write a comment