Skip to content

Commit 9760887

Browse files
committed
Add some docs
1 parent 6cd3449 commit 9760887

File tree

1 file changed

+12
-2
lines changed
  • app/services/discourse_translator

1 file changed

+12
-2
lines changed

app/services/discourse_translator/base.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def self.cache_key
2424
"#{key_prefix}#{access_token_key}"
2525
end
2626

27+
# Returns the stored translation of a post or topic.
28+
# If the translation does not exist yet, it will be translated first via the API then stored.
29+
# If the detected language is the same as the target language, the original text will be returned.
30+
# @param topic_or_post [Post|Topic]
2731
def self.translate(topic_or_post)
2832
return if text_for_translation(topic_or_post).blank?
2933
detected_lang = detect(topic_or_post)
@@ -39,12 +43,15 @@ def self.translate(topic_or_post)
3943
)
4044
end
4145

42-
translated_text = translate!(topic_or_post)
46+
translated_text = get_detected_locale(topic_or_post) || translate!(topic_or_post)
4347

4448
[detected_lang, translated_text]
4549
end
4650

47-
def self.translate!(post)
51+
# Subclasses must implement this method to translate the text of a post or topic
52+
# then use the save_translation method to store the translated text.
53+
# @param topic_or_post [Post|Topic]
54+
def self.translate!(topic_or_post)
4855
raise "Not Implemented"
4956
end
5057

@@ -56,6 +63,9 @@ def self.detect(topic_or_post)
5663
get_detected_locale(topic_or_post) || detect!(topic_or_post)
5764
end
5865

66+
# Subclasses must implement this method to translate the text of a post or topic
67+
# then use the save_translation method to store the translated text.
68+
# @param topic_or_post [Post|Topic]
5969
def self.detect!(post)
6070
raise "Not Implemented"
6171
end

0 commit comments

Comments
 (0)