Skip to content

Commit

Permalink
website: Use existing translations of language names (#1349)
Browse files Browse the repository at this point in the history
Removed language.json translation file as we don't really need it anymore, just moved the couple of remaining items into tasks.json

I also reverted the change where I created lang_mismatch_lang and lang_mismatch_lang.explanation because we don't actually need two different strings and it was causing an issue where it would show a mix of english and the users language rather than just show the existing "Wrong language" text that is probably a better intermediate until the translations are updated. Let me know if there is a better way to handle updating the source english text for translations.
  • Loading branch information
othrayte authored Feb 8, 2023
1 parent e6b574e commit db76b0b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 38 deletions.
6 changes: 2 additions & 4 deletions website/public/locales/en/labelling.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
"label_message_flag_instruction": "Select any that apply to the message:",
"label_message_likert_instruction": "Rate the message:",
"label_message_yes_no_instruction": "Answer the following question(s) about the message:",
"lang_mismatch": "Wrong Language",
"lang_mismatch.explanation": "Not written in the currently selected language.",
"lang_mismatch_lang": "Not {{language}}",
"lang_mismatch_lang.explanation": "Not written in {{language}}.",
"lang_mismatch": "Not {{language}}",
"lang_mismatch.explanation": "Not written in {{language}}.",
"moral_judgement": "Judges Morality",
"moral_judgement.explanation": "Expresses moral judgement.",
"not_appropriate": "Not Appropriate",
Expand Down
22 changes: 0 additions & 22 deletions website/public/locales/en/language.json

This file was deleted.

4 changes: 3 additions & 1 deletion website/public/locales/en/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@
"desc": "Provide labels for a prompt.",
"overview": "Read the following conversation and then answer the question about the last reply in the discussion."
},
"available_task_count": "{{count}} tasks available"
"available_task_count": "{{count}} tasks available",
"writing_wrong_langauge_a_b": "You appear to be writing in {{detected_lang}} but this will be submitted as {{submit_lang}}.",
"submitted_as": "This will be submitted as {{submit_lang}}"
}
11 changes: 7 additions & 4 deletions website/src/components/Messages/LabelFlagGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, Flex, Tooltip } from "@chakra-ui/react";
import { useTranslation } from "next-i18next";
import { useCookies } from "react-cookie";
import { getTypeSafei18nKey } from "src/lib/i18n";

interface LabelFlagGroupProps {
Expand All @@ -17,14 +18,16 @@ export const LabelFlagGroup = ({
isEditable = true,
onChange,
}: LabelFlagGroupProps) => {
const { t } = useTranslation(["labelling", "language"]);
const expectedLanguageName = t(getTypeSafei18nKey(`language:lang_${expectedLanguage}`));
const { t } = useTranslation("labelling");
const [cookies] = useCookies(["NEXT_LOCALE"]);
const currentLanguage = cookies["NEXT_LOCALE"];
const expectedLanguageName = new Intl.DisplayNames(currentLanguage, { type: "language" }).of(expectedLanguage);
return (
<Flex wrap="wrap" gap="4">
{labelNames.map((name, idx) => (
<Tooltip
key={name}
label={`${t(getTypeSafei18nKey(`${name}_lang.explanation`), t(getTypeSafei18nKey(`${name}.explanation`)), {
label={`${t(getTypeSafei18nKey(`${name}.explanation`), `${name}.explanation`, {
language: expectedLanguageName,
})}`}
>
Expand All @@ -37,7 +40,7 @@ export const LabelFlagGroup = ({
isDisabled={!isEditable}
colorScheme={values[idx] === 1 ? "blue" : undefined}
>
{t(getTypeSafei18nKey(`${name}_lang`), t(getTypeSafei18nKey(name)), { language: expectedLanguageName })}
{t(getTypeSafei18nKey(`${name}`), name, { language: expectedLanguageName })}
</Button>
</Tooltip>
))}
Expand Down
9 changes: 4 additions & 5 deletions website/src/components/Survey/TrackedTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import lande from "lande";
import { useTranslation } from "next-i18next";
import React from "react";
import { useCookies } from "react-cookie";
import { getTypeSafei18nKey } from "src/lib/i18n";
import { LanguageAbbreviations } from "src/lib/iso6393";
import { colors } from "src/styles/Theme/colors";

Expand All @@ -20,12 +19,12 @@ interface TrackedTextboxProps {
}

export const TrackedTextarea = (props: TrackedTextboxProps) => {
const { t } = useTranslation("language");
const { t } = useTranslation("tasks");
const wordLimitForLangDetection = 4;
const backgroundColor = useColorModeValue("gray.100", "gray.900");
const [cookies] = useCookies(["NEXT_LOCALE"]);
const wordCount = (props.text.match(/\w+/g) || []).length;
const currentLanguage = cookies["NEXT_LOCALE"];
const wordCount = (props.text.match(/\w+/g) || []).length;

const detectLang = (text: string) => {
try {
Expand Down Expand Up @@ -81,8 +80,8 @@ export const TrackedTextarea = (props: TrackedTextboxProps) => {
>
<Tooltip
label={t(wrongLanguage ? "writing_wrong_langauge_a_b" : "submitted_as", {
submit_lang: t(getTypeSafei18nKey(`lang_${currentLanguage}`), currentLanguage),
detected_lang: t(getTypeSafei18nKey(`lang_${detectedLang}`), detectedLang),
submit_lang: new Intl.DisplayNames(currentLanguage, { type: "language" }).of(currentLanguage),
detected_lang: new Intl.DisplayNames(currentLanguage, { type: "language" }).of(detectedLang),
})}
>
{detectedLang}
Expand Down
2 changes: 0 additions & 2 deletions website/types/i18next.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type common from "public/locales/en/common.json";
import type dashboard from "public/locales/en/dashboard.json";
import type index from "public/locales/en/index.json";
import type labelling from "public/locales/en/labelling.json";
import type language from "public/locales/en/language.json";
import type leaderboard from "public/locales/en/leaderboard.json";
import type message from "public/locales/en/message.json";
import type side_menu from "public/locales/en/side_menu.json";
Expand All @@ -19,7 +18,6 @@ declare module "i18next" {
tasks: typeof tasks;
message: typeof message;
labelling: typeof labelling;
language: typeof language;
side_menu: typeof side_menu;
tos: typeof tos;
};
Expand Down

0 comments on commit db76b0b

Please sign in to comment.