mirror of
https://github.com/funamitech/mastodon
synced 2024-11-27 22:38:42 +09: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'
|
||||
@filter = :language
|
||||
@type = :term
|
||||
@term = term
|
||||
@term = language_code_from_term(term)
|
||||
when 'from'
|
||||
@filter = :account_id
|
||||
@type = :term
|
||||
@ -137,6 +137,22 @@ class SearchQueryTransformer < Parslet::Transform
|
||||
# an ID that does not exist
|
||||
account&.id || -1
|
||||
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
|
||||
|
||||
rule(clause: subtree(:clause)) do
|
||||
|
Loading…
Reference in New Issue
Block a user