@@ -28,21 +28,23 @@ def self.cache_key
2828 # If the translation does not exist yet, it will be translated first via the API then stored.
2929 # If the detected language is the same as the target language, the original text will be returned.
3030 # @param translatable [Post|Topic]
31- def self . translate ( translatable )
31+ def self . translate ( translatable , target_locale_sym = I18n . locale )
3232 return if text_for_translation ( translatable ) . blank?
3333 detected_lang = detect ( translatable )
3434
35- return detected_lang , get_text ( translatable ) if ( detected_lang &.to_s == I18n . locale . to_s )
35+ if translatable . locale_matches? ( target_locale_sym )
36+ return detected_lang , get_text ( translatable )
37+ end
3638
37- existing_translation = get_translation ( translatable )
38- return detected_lang , existing_translation if existing_translation . present?
39+ translation = translatable . translation_for ( target_locale_sym )
40+ return detected_lang , translation if translation . present?
3941
40- unless translate_supported? ( detected_lang , I18n . locale )
42+ unless translate_supported? ( detected_lang , target_locale_sym )
4143 raise TranslatorError . new (
4244 I18n . t (
4345 "translator.failed" ,
4446 source_locale : detected_lang ,
45- target_locale : I18n . locale ,
47+ target_locale : target_locale_sym ,
4648 ) ,
4749 )
4850 end
@@ -52,7 +54,7 @@ def self.translate(translatable)
5254 # Subclasses must implement this method to translate the text of a post or topic
5355 # then use the save_translation method to store the translated text.
5456 # @param translatable [Post|Topic]
55- def self . translate! ( translatable )
57+ def self . translate! ( translatable , target_locale_sym = I18n . locale )
5658 raise "Not Implemented"
5759 end
5860
@@ -75,10 +77,6 @@ def self.access_token
7577 raise "Not Implemented"
7678 end
7779
78- def self . get_translation ( translatable )
79- translatable . translation_for ( I18n . locale )
80- end
81-
8280 def self . save_translation ( translatable )
8381 translation = yield
8482 translatable . set_translation ( I18n . locale , translation )
0 commit comments