Does anyone know a way to query the logged-in account's locale (= display language) using the Mastodon API? From what I can tell, I need this to determine whether to show the Translate button or not.
There is the "posting:default:language" preference which I've been using so far. But from what I can tell, this has nothing to do with what language Mastodon's translation feature will translate to – plus it can be null.
I looked at how the official web app is doing it, and seems like the locale is passed down using HTML instead of queried using the API:
<div
class='app-holder'
id='mastodon'
data-props='{"locale:"en"}'`>
Leaves me wondering: Is there an API endpoint that gives me the user's locale, or do I have to scrape this information from the HTML?
For reference: The web frontend determines whether to show the translation button like this:
this.props.onTranslate
&& this.context.identity.signedIn
&& ['public', 'unlisted']
.includes(status.get('visibility'))
&& status.get('contentHtml').length > 0
&& targetLanguages
?.includes(intl.locale.replace(/[_-].*/, ''));
…with `intl.locale` being what's passed in from `data-props`.
@megalodon The current way its done here, its by this piece of code: !item.status.language.equalsIgnoreCase(item.session.preferences.postingDefaultLanguage)
@moshidon yeah, as far as i can remember, i wrote that, but, again, users can set their default posting language to any language, even if it's not their display language (aka locale) - and it's null by default