LiteralTerm.withLanguage constructor
Create a language-tagged literal
This is a convenience factory for creating literals with language tags. These literals use the rdf:langString datatype as required by the RDF 1.1 specification.
Parameters:
value
The string value of the literallangTag
The language tag (e.g., "en", "de", "fr-CA") following BCP 47 format
Returns: A new LiteralTerm with the specified value, rdf:langString datatype, and language tag
Note: Language tags are case-insensitive according to the RDF specification, but it's recommended to use lowercase for language subtags (e.g., "en-us" rather than "en-US") for maximum compatibility.
Example:
// Create an English language literal
final enLiteral = LiteralTerm.withLanguage("Hello", "en");
// Create a German language literal
final deLiteral = LiteralTerm.withLanguage("Hallo", "de");
// Create a Canadian French literal with region subtag
final frCALiteral = LiteralTerm.withLanguage("Bonjour", "fr-ca");
Implementation
factory LiteralTerm.withLanguage(String value, String langTag) {
return LiteralTerm(value, datatype: Rdf.langString, language: langTag);
}