mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-24 15:54:48 +00:00
Change language:
to attempt to match to a known value in search (#26663)
This commit is contained in:
parent
0e1bff178e
commit
bba76e7267
|
@ -98,7 +98,7 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
when 'language'
|
when 'language'
|
||||||
@filter = :language
|
@filter = :language
|
||||||
@type = :term
|
@type = :term
|
||||||
@term = term
|
@term = language_code_from_term(term)
|
||||||
when 'from'
|
when 'from'
|
||||||
@filter = :account_id
|
@filter = :account_id
|
||||||
@type = :term
|
@type = :term
|
||||||
|
@ -137,6 +137,22 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
# an ID that does not exist
|
# an ID that does not exist
|
||||||
account&.id || -1
|
account&.id || -1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def language_code_from_term(term)
|
||||||
|
language_code = term
|
||||||
|
|
||||||
|
return language_code if LanguagesHelper::SUPPORTED_LOCALES.key?(language_code.to_sym)
|
||||||
|
|
||||||
|
language_code = term.downcase
|
||||||
|
|
||||||
|
return language_code if LanguagesHelper::SUPPORTED_LOCALES.key?(language_code.to_sym)
|
||||||
|
|
||||||
|
language_code = term.split(/[_-]/).first.downcase
|
||||||
|
|
||||||
|
return language_code if LanguagesHelper::SUPPORTED_LOCALES.key?(language_code.to_sym)
|
||||||
|
|
||||||
|
term
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rule(clause: subtree(:clause)) do
|
rule(clause: subtree(:clause)) do
|
||||||
|
|
Loading…
Reference in a new issue