I’m attempting to modify certain strings on the user preferences page. I navigated to Admin → Site Texts and searched for the relevant keys. However, I was unable to customize the specific text I was looking for as it told me there were no texts found.
I am reasonably certain that the key is valid, as it is defined here:
I then switched the target language to English but still yielded no results for user.username.short_instructions. Furthermore, I attempted to search for other strings such as user.username.title, user.preferences.title, and filters.latest.title, and no results either.
It looks like there are no related errors, and based on the request results, it may be a backend issue.
Although I don’t believe the plugins I’ve installed have modified this particular area, I will attempt to remove all unofficial plugins later to see if that resolves the problem.
I have some updates regarding this matter. I can now definitively confirm that the issue lies with the backend. While examining the code, I noticed a particular line:
To my surprise, executing I18n.exists?("js.user.username.short_instructions", :en) on my instance returns false.
I am uncertain as to why I18n.exists?("js.user.username.short_instructions", :en) is returning false. I may investigate further to determine whether the problem is specific to my instance or a more general issue with Discourse.
@sam, thank you for your response. I’ve deployed three Discourse instances using different methods, and all exhibit the same issue, leading me to believe it’s not an installation problem.
Upon re-examining my plugins, I discovered that one of them created a locale file (plugins/XXXX/config/locales/client.en.yml) with the following content:
en:
js:
Deleting this file resolved the problem. After a brief investigation into the I18n implementation, I found that deep_merge is used to merge translations during loading:
# File activesupport/lib/active_support/vendor/i18n-0.4.1/i18n/backend/simple.rb, line 31
31: def store_translations(locale, data, options = {})
32: locale = locale.to_sym
33: translations[locale] ||= {}
34: data = data.deep_symbolize_keys
35: translations[locale].deep_merge!(data)
36: end
The YAML above is parsed as:
{"en": {"js": null}}
This results in the deletion of the entire content under the en.js key after the merge. As a plugin developer, I understand that this issue stems from my own coding error, and I am fully responsible for it. However, I believe Discourse could benefit from additional checks to warn against such occurrences, especially considering that Discourse already has a design for inspecting locale files, as seen here.
You are correct. I made an unwarranted assumption that these checks would execute at runtime. Upon searching the GitHub repository, it appears these checks are invoked solely within a rake task:
Adding checks here would not have preemptively identified the issue I encountered. Perhaps the most straightforward solution is to caution developers against this practice in the documentation