LiteralMapping.withLanguage constructor

const LiteralMapping.withLanguage(
  1. String language
)

Specifies a language tag for string literals at the property level.

This constructor creates a mapping that will apply the given language tag to string values when serialized as RDF literals. This is particularly useful for human-readable text that appears in a specific language.

Important: This mapping delegates to the registered mapper for the property's type and then applies the language tag to the result. This means the property's type must have a registered mapper available (built-in for primitives, generated from annotations, or explicitly registered).

The language parameter must be a valid BCP47 language tag (e.g., 'en', 'de-DE').

Example with String property:

@RdfGlobalResource(...)
class TravelGuide {
  @RdfProperty(
    TourismSchema.description,
    literal: LiteralMapping.withLanguage('en')
  )
  final String description; // Will be serialized as "description"@en
}

Example with annotated enum property:

@RdfLiteral() // Creates registered mapper
enum Status {
  @RdfEnumValue('active')
  active,
  inactive,
}

@RdfGlobalResource(...)
class Task {
  @RdfProperty(
    TaskSchema.status,
    literal: LiteralMapping.withLanguage('en')
  )
  final Status status; // Uses registered enum mapper + applies @en language tag
}

Implementation

const LiteralMapping.withLanguage(String language)
    : language = language,
      datatype = null,
      super();