Language Configuration Guide#

Drawing Tools uses language configurations to parse view titles in multiple languages. This guide explains how to use and customize these configurations, so that properties like view name, type, scale, repetition are parsed correctly for each language.

Overview#

Technical drawings often contain text in multiple languages. The LanguageConfig class defines patterns and keywords for parsing title information (view names, scales, repetitions) in a specific language.

from drawing_tools.config.default_language_configs import DEFAULT_ENGLISH_CONFIG, DEFAULT_FRENCH_CONFIG

# Use predefined configurations
language_configs = [DEFAULT_FRENCH_CONFIG, DEFAULT_ENGLISH_CONFIG]

Pre-defined Configurations#

Drawing Tools provides two ready-to-use configurations:

DEFAULT_FRENCH_CONFIG#

Configured for French technical drawings:

  • View keywords: “VUE DE FACE”, “VUE DE FACE H/C”, “COUPE”, “SECTION” (section cut), “VUE ISOMETRIQUE”, “DETAIL”, “VUE SUIVANT F”, “VUE DE DESSUS H/C”

  • Scale patterns: “ECH: 2:1”, “ÉCHELLE 1:1”

  • Repetition patterns: “VALABLE 2 FOIS”, “VALABLE DEUX FOIS”

DEFAULT_ENGLISH_CONFIG#

Configured for English technical drawings:

  • View keywords: “FRONT VIEW”, “H/C FRONT VIEW”, “SECTION VIEW”, “SECTION CUT” (section cut), “ISOMETRIC VIEW”, “DETAIL VIEW”, “VIEW ON F”, “H/C TOP VIEW”

  • Scale patterns: “SCALE: 2:1”, “SCALE 1:1”

  • Repetition patterns: “VALID 2 TIMES”, “VALID TWICE”

These configurations are only examples, and can be customized to fit the needs of the project.

LanguageConfig Structure#

A LanguageConfig contains several components:

Basic Properties#

from drawing_tools.config.view_language_configs import LanguageConfig

config = LanguageConfig(
    name="french",      # Human-readable name
    code="fr",          # ISO 639-1 code
    # ... other parameters
)

Scale Patterns#

Regex patterns for detecting scale information:

import re

scale_patterns = [
    re.compile(r"ECH[./:]?\s*(?:SCALE)?\s*[:=]?\s*(\d+\s*:\s*\d+)", re.I),
    re.compile(r"É?CHELLE\s*[:=]?\s*(\d+\s*:\s*\d+)", re.I),
    re.compile(r"(\d+\s*:\s*\d+)", re.I),  # Fallback: bare scale format
]

Important: Patterns are checked in order. Place more specific (often longer patterns) first to avoid false positives. This prevents the general pattern from matching before the specific one has a chance.

Repetition Patterns#

Patterns for detecting how many times the information on a view should apply:

# Numeric patterns (e.g., "VALID 2 TIMES")
numeric_repetition_patterns = [
    re.compile(r"VALABLE\s+(\d+)\s+FOIS", re.I),
    re.compile(r"(\d+)\s*[Xx]", re.I),  # e.g., "2x"
]

# Word patterns (e.g., "VALID TWICE")
word_repetition_patterns = [
    re.compile(r"VALABLE\s+(\w+)\s+FOIS", re.I),
]

# Word to number mapping
word_to_number = {
    "un": 1, "une": 1,
    "deux": 2,
    "trois": 3,
    # ...
}

Important: Same remark here on the importance of the order of the patterns.

View Keywords#

Keywords for identifying view names:

# Keywords that indicate a line IS a view name
view_keywords = [
    "VUE DE FACE",
    "COUPE",
    "VUE ISOMETRIQUE",
    "DETAIL",
    "VUE SUIVANT F",
]

# Keywords that indicate a line is NOT a view name
non_view_keywords = ["ECH", "ÉCHELLE", "VALABLE"]

View Type Identification#

Mapping from keywords to ViewType enum values:

from drawing_tools.config.view_types_config import ViewType

view_type_identification_keywords = {
    "VUE DE FACE": ViewType.FRONT_VIEW,
    "COUPE": ViewType.SECTION_VIEW,
    "VUE ISOMETRIQUE": ViewType.ISOMETRIC_VIEW,
    "DETAIL": ViewType.DETAIL_VIEW,
    "VUE SUIVANT F": ViewType.AUXILIARY_VIEW,
}

ViewType Enumeration#

The ViewType enum defines all recognized view types:

from drawing_tools.config.view_types_config import ViewType

# Available view types
ViewType.FRONT_VIEW        # Main/front views (FR: "VUE DE FACE", EN: "FRONT VIEW")
ViewType.SECTION_VIEW      # Section views showing cut + behind (FR: "COUPE", EN: "SECTION VIEW")
ViewType.SECTION_CUT       # Section cuts showing only cut surface (FR: "SECTION", EN: "SECTION CUT")
ViewType.DETAIL_VIEW       # Detail views (zoomed areas)
ViewType.AUXILIARY_VIEW    # Auxiliary/projection views
ViewType.ISOMETRIC_VIEW    # Isometric/3D views
ViewType.TOP_VIEW          # Top views (FR: "VUE DE DESSUS", EN: "TOP VIEW")
ViewType.BOTTOM_VIEW       # Bottom views
ViewType.LHS_VIEW          # Left-hand side views
ViewType.RHS_VIEW          # Right-hand side views
ViewType.REAR_VIEW         # Rear views
ViewType.UNFOLDED_VIEW     # Unfolded views
ViewType.EXPLODED_VIEW     # Exploded views
ViewType.LEVELED_SECTION_VIEW   # Leveled (straightened) section views
ViewType.ROTATED_VIEW_ON       # Rotated views
ViewType.TYP_SECTION_VIEW      # Typical section views (FR: "COUPE ... TYP.", EN: "TYP. SECTION VIEW")
ViewType.TYP_SECTION_CUT       # Typical section cuts (FR: "SECTION ... TYP.", EN: "TYP. SECTION CUT")
ViewType.BACKGROUND_VIEW   # Title block, borders

# Get all types
all_types = ViewType.all_types()

# View type groups allow treating related types together
from drawing_tools.config.view_types_config import VIEW_TYPE_GROUPS

# Example: check if a view is any kind of section
group = ViewType.get_group(ViewType.SECTION_CUT)
# Returns: [SECTION_VIEW, SECTION_CUT, LEVELED_SECTION_VIEW, TYP_SECTION_VIEW, TYP_SECTION_CUT]

Creating a Custom Configuration#

To support a new language (e.g., German):

from drawing_tools.config.view_language_configs import LanguageConfig, ViewTypePatterns
from drawing_tools.config.view_types_config import ViewType

GERMAN_CONFIG = LanguageConfig(
    name="german",
    code="de",
    scale_patterns=[
        r"MASSSTAB\s*[:=]?\s*(\d+\s*:\s*\d+)",
        r"M\s*[:=]?\s*(\d+\s*:\s*\d+)",
        r"(\d+\s*:\s*\d+)",
    ],
    numeric_repetition_patterns=[
        r"GÜLTIG\s+(\d+)\s+MAL",
        r"(\d+)\s*[Xx]",
    ],
    word_repetition_patterns=[
        r"GÜLTIG\s+(\w+)\s+MAL",
    ],
    view_type_patterns=ViewTypePatterns(
        patterns_by_type={
            "front_view": [r"VORDERANSICHT"],
            "section_view": [r"SCHNITT"],
            "isometric_view": [r"ISOMETRISCHE\s+ANSICHT"],
            "detail_view": [r"EINZELHEIT"],
            "auxiliary_view": [r"ANSICHT"],
        }
    ),
    word_to_number={
        "eins": 1,
        "zwei": 2,
        "drei": 3,
        "vier": 4,
        "fünf": 5,
    },
)

Using Multiple Languages#

When parsing drawings with multiple languages, provide all relevant configurations:

from drawing_tools.featured_drawing import FeaturedDrawing
from drawing_tools.config.default_language_configs import DEFAULT_ENGLISH_CONFIG, DEFAULT_FRENCH_CONFIG

# Both languages will be parsed
featured_drawing = FeaturedDrawing(
    drawing,
    language_configs=[DEFAULT_FRENCH_CONFIG, DEFAULT_ENGLISH_CONFIG]
)

# Access results by language
for view in featured_drawing.sheets[0].views:
    if view.title:
        # French result
        french_name = view.title.view_name_by_language.get("french")
        # English result
        english_name = view.title.view_name_by_language.get("english")