instructure/canvas-lms · error · Translation::UnsupportedLanguageError
UnsupportedLanguageError
Error message
UnsupportedLanguageError
What it means
Raised by handle_cedar_errors in lib/translation.rb:141 when the Cedar translation service reports an UnsupportedLanguageError. The wrapper translates the upstream exception into Canvas's own UnsupportedLanguageError so callers get a consistent error type. It means one of the source or target languages passed to translate_text/translate_html is not supported by the translation backend.
Solutions
- Check the source/target language codes against the translation service's supported language list before calling translate_text/translate_html
- Normalize/validate locale codes (format, casing, region) before submission
- Rescue UnsupportedLanguageError and fall back to a default supported language or skip translation
- Verify the translation backend configuration/version still supports the requested languages
Example fix
// before Translation::Service.translate_text(text, from: 'zh_CN', to: 'jp') // after raise UnsupportedLanguageError unless SUPPORTED_LANGUAGES.include?(to) Translation::Service.translate_text(text, from: 'zh-CN', to: 'ja')
Defensive patterns
Strategy: validation
Validate before calling
raise UnsupportedLanguageError unless SUPPORTED_LANGUAGES.include?(target_locale) && SUPPORTED_LANGUAGES.include?(source_locale)
Try / catch
begin translate_text(text, from:, to:) rescue UnsupportedLanguageError fallback_locale_translation(text) end
Prevention
- Validate locale codes against the service's supported list before calling
- Normalize locale format (BCP-47) consistently
- Keep a monitored list of supported languages
When it happens
Trigger: Calling translate_text or translate_html with a locale string the Cedar service does not recognize (malformed code, deprecated locale, or a language outside Cedar's supported set); Cedar returns UnsupportedLanguageError which the case/when block remaps.
Common situations: Hardcoded locale strings that drift from supported language lists; user-submitted target languages not validated against the supported set; locale codes with wrong casing or region suffixes; backend language list changed after an upgrade.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- e.message
- format must be one of #
- SameLanguageTranslationError
- TextTooLongError
- Translation::SameLanguageTranslationError
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/bf443356686052b1.
Report an issue: GitHub.
Appendix: source
Thrown at lib/translation.rb:141
raise Translation::SameLanguageTranslationError
end
end
def collect_translation_stats(src_lang:, tgt_lang:, type:)
tags = %W[type:#{type} source_language:#{src_lang} dest_language:#{tgt_lang}]
InstStatsd::Statsd.distributed_increment("translation.invocations", tags:)
end
def handle_cedar_errors
yield
rescue => e
case e.class.name
when /SameLanguageTranslationError/
raise SameLanguageTranslationError
when /ContentTooLongError/
raise TextTooLongError
when /UnsupportedLanguageError/
raise UnsupportedLanguageError
when /ValidationError/
raise ValidationError
else
raise TranslationError, e.message
end
end
end
end
View on GitHub (pinned to 1c9f0bb801)