Use multiple LEFT JOIN
clauses.
SELECT a.*, IFNULL(p.text, e.text) AS text
FROM table AS a
LEFT JOIN translate AS p ON p.key = a.key AND p.language = 'ptbr'
LEFT JOIN translate AS e ON e.key = a.key AND e.i18n = 'enus'
The subquery that will do what you want is:
SELECT text
FROM (SELECT 1 AS priority, text
FROM translate
WHERE key = A.key
AND language = 'ptbr'
UNION
SELECT 2 AS priority, text
FROM translate
WHERE key = A.key
AND i18n = 'enus') x
ORDER BY priority
LIMIT 1
Or you could do:
SELECT text
FROM translate
WHERE key = A.key
AND (language = "ptbr" or i18n = "enus")
ORDER BY language = "ptbr" DESC
LIMIT 1
The general point is that if you want LIMIT 1
to return a preferred row, you need to use ORDER BY
to ensure that this row is first in the results.