---
title: "Use OpenType localized forms in C#"
url: https://recursiveai.org/onefont/cookbook/shape-text-with-locale-specific-glyphs/
description: "Select OpenType localized glyphs with a language tag in C#. Shape Cyrillic б as Russian and Serbian and compare glyph IDs from the same font."
version: "1.4.0"
---

# Use OpenType localized forms in C#

**onefont** is a free, open-source font and text-shaping library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneFont) · [GitHub](https://github.com/recursive-ai-oss/onefont-csharp) · [Docs](https://recursiveai.org/onefont/docs/) · [Download example (.zip)](https://recursiveai.org/onefont/cookbook/shape-text-with-locale-specific-glyphs/shape-text-with-locale-specific-glyphs.zip)

Some languages draw the same letter differently, and the font uses the language tag to pick the form. In the zip’s `sans.ttf`, Russian `б` looks like a 6, while Serbian `б` has an S-shaped stroke above its loop.

```shell
dotnet add package RecursiveAI.OneFont
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneFont;

var face = FontFace.Load(
    File.ReadAllBytes("sans.ttf"));
Console.WriteLine($"ru: {Glyph("ru")}");
Console.WriteLine($"sr: {Glyph("sr")}");

int Glyph(string lang)
{
    var options = new ShapingOptions
        { Language = lang };
    var run = TextShaping.ShapeRun(
        "б", face, options: options);
    return run[0].Glyphs[0].GlyphId;
}
```

Unzip [the example](https://recursiveai.org/onefont/cookbook/shape-text-with-locale-specific-glyphs/shape-text-with-locale-specific-glyphs.zip), then `dotnet run`.

Prints the glyph ID for Cyrillic `б` in each language:

```text
ru: 290
sr: 419
```

If your font has no matching language system, OneFont uses the script’s default. If the language exists but has no applicable substitution, that character can still get the same glyph.

## Variations

### Keep Serbian but turn localized forms off

To turn off localized forms (`locl`), replace the options declaration in `Glyph`:

```csharp
var options = new ShapingOptions
    { Language = lang };
options.Features.Add(FontFeature.Off("locl"));
```

```text
ru: 290
sr: 290
```

## Related recipes

- [Use OpenType features](https://recursiveai.org/onefont/cookbook/opentype-features/)
- [Shape text](https://recursiveai.org/onefont/cookbook/shape-text/)
- [Shape text with font fallback](https://recursiveai.org/onefont/cookbook/shape-text-with-font-fallback/)

---

## The short answer

Pass a language tag in `ShapingOptions.Language` when you call `TextShaping.ShapeRun`. For horizontal text `locl` is on by default. You need a font with a localized substitution for that script, language, and character. In the bundled face, setting the language to `sr` changes the glyph for `б` from 290 to 419; the string is still `б`.

## What are OpenType localized forms?

[`locl`, or localized forms](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#tag-locl), is an OpenType substitution feature. It lets a font substitute a glyph preferred by a language that shares its writing script with other languages. It doesn’t translate text or replace Unicode characters. Use the original string for storage and search, and the shaped glyph IDs with the same face for drawing. Glyph IDs belong to the font, so don’t expect another face to use 419 for the same form.

OneFont applies `ccmp` and `locl` before the later shaping features, as described in the [shaping guide](https://recursiveai.org/onefont/docs/shaping/). Looking up the character with `GetGlyphIndex` alone reads its default mapping, not the localized substitution. Shaping the same string under two languages isolates the difference in this example.

## What language tag enables an OpenType localized form?

Use the language of the text, not the language of the application interface. OneFont accepts a BCP 47 language tag such as `sr`, or an uppercase OpenType language tag such as `SRB`. The library selects the font’s language system for the script in the run; a tag alone can’t supply a form the font doesn’t have. When a document mixes languages within the same script, shape each language’s span with its own options.

To diagnose an unchanged result, start with a character known to have an alternate in the font, check its language tag and compare the glyph IDs under the two settings. Also check that your feature list hasn’t turned `locl` off.
