From 6e1c53015cc38e06331382392b3ade2b5e133930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michelle=20=22MishManners=C2=AE=E2=84=A2=22=20Duke?= <36594527+mishmanners@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:21:50 +1000 Subject: [PATCH 1/2] Update a bit of README and update versions --- README.md | 2 ++ package-lock.json | 28 ++++++++++++++-------------- src/pages/about.astro | 2 +- src/pages/about.md | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 690598c6..c6e4b1cf 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Do you have dietary requirements or allergies? Do you travel a lot? :train: 🚌 Mish Friendly Food will translate your dietary requirements/allergies into any language 🤯. Enter your details and choose your desired language. Once you have your translation, you can get it printed on a cute card, or text the results to your phone (coming soon). Next time you travel to foreign country, you can pull out your physical or digital card, and rest assured that your waiter, host, or chef, will know how to cater for you. +Note, the digital card is still coming. + **[The website](https://mishfriendlyfood.com/) is now live** thanks to the contributions of this awesome community. You can find the website at [mishfriendlyfood.com](https://mishfriendlyfood.com/). Currently, the website only contains an About Page, and list of Translations. If you'd like to help with phase two of the project (search the database and retrieve; see [Phase Two](https://mishfriendlyfood.com/) below), then please take a look at the contribution guidelines below and join the project. We'd love the help :heart:. ## About diff --git a/package-lock.json b/package-lock.json index ed219b43..4c764b83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1217,11 +1217,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -2160,9 +2160,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -7283,11 +7283,11 @@ } }, "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "requires": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" } }, "browserslist": { @@ -7824,9 +7824,9 @@ } }, "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "requires": { "to-regex-range": "^5.0.1" } diff --git a/src/pages/about.astro b/src/pages/about.astro index 884f0fa7..6f749fc2 100644 --- a/src/pages/about.astro +++ b/src/pages/about.astro @@ -14,7 +14,7 @@ const meta = {

Mish Friendly Food will translate your dietary requirements/allergies into any language. Once you have your translation, you can get it - printed on a cute card. Next time you travel to foreign country, you can + printed on a cute card. Note this features is still coming. Next time you travel to foreign country, you can pull out your physical or digital card and rest assured that your waiter, host, or chef, will know how to cater for you.

diff --git a/src/pages/about.md b/src/pages/about.md index ffc50c69..432319e2 100644 --- a/src/pages/about.md +++ b/src/pages/about.md @@ -9,7 +9,7 @@ Mish Friendly Food will translate your dietary requirements/allergies into any language. Once you have your translation, you can get it printed on a cute card. Next time you travel to foreign country, you can pull out your physical or digital card and rest assured that your -waiter, host, or chef, will know how to cater for you. +waiter, host, or chef, will know how to cater for you. Note this card features is still coming. ## Why Mish Friendly Food? From 3b514a389c59c7778fb50753e36a0452e13b66fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michelle=20=22MishManners=C2=AE=E2=84=A2=22=20Duke?= <36594527+mishmanners@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:38:55 +1000 Subject: [PATCH 2/2] Add mult-word translation support Supports the translation of multiple words at once. Added tests to check that this works and displays correctly. --- src/components/client/Search.jsx | 33 +++++++++++++++++-------- tests/translations.spec.js | 42 +++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/components/client/Search.jsx b/src/components/client/Search.jsx index 64ffe1a3..618893a1 100644 --- a/src/components/client/Search.jsx +++ b/src/components/client/Search.jsx @@ -54,19 +54,25 @@ export const Search = () => { const fromLanguage = formData.get('fromLanguage'); const toLanguage = formData.get('toLanguage'); - // Get the search query from the form input - const word = formData.get('wordSearch').trim().toLowerCase(); + // Split the search query on comma + const words = formData.get('wordSearch').split(',').map((word) => word.trim().toLowerCase()); if (fromLanguage && toLanguage) { // Initialize an object to store the translation results let translations = []; - // Retrieve translations for the selected languages - try { - translations.push([word, getTranslationsForLanguages(fromLanguage, toLanguage, word)]); - } catch(e) { - translations.push([word, toError(e)]); - } + // Iterate over each unique word and perform translation + new Set(words).forEach((word) => { + // Retrieve translations for the selected languages + try { + translations.push([ + word, + getTranslationsForLanguages(fromLanguage, toLanguage, word) + ]); + } catch(e) { + translations.push([word, toError(e)]); + } + }); // Display translations to the user as needed setTranslationResults(translations); @@ -104,8 +110,15 @@ export const Search = () => { {/* Display translation results */}

Translation Results

diff --git a/tests/translations.spec.js b/tests/translations.spec.js index d3597a27..aa95e231 100644 --- a/tests/translations.spec.js +++ b/tests/translations.spec.js @@ -21,7 +21,7 @@ test("can translate a word", async ({ page }) => { await page.getByRole("button", { name: "Translate" }).click(); await expect( - page.getByTestId("translation-results").locator("> li") + page.getByTestId("translation-results").locator("li li") ).toHaveText([/Milch/, /Milchprodukt/]); }); @@ -38,3 +38,43 @@ test("shows an error when there is no translation", async ({ page }) => { /Translations not found for selected language combination/ ); }); + +test("translates food dietaries", async ({ page }) => { + await page.goto("/translations"); + + await page.getByLabel("From").selectOption("English"); + await page.getByLabel("To").selectOption("French"); + await page.getByLabel("Word").fill("gluten-free, vegan, dairy-free"); + + await page.getByRole("button", { name: "Translate" }).click(); + + await expect( + page.getByTestId("translation-results").locator("li li") + ).toHaveText([ + /sans gluten/i, + /végétalienne/i, + /végétalien/i, + /végan/i, + /sans lactose/i, + /sans produits laitiers/i, + ]); +}); + +test("deduplicates words in search field", async ({ page }) => { + await page.goto("/translations"); + + await page.getByLabel("From").selectOption("English"); + await page.getByLabel("To").selectOption("German"); + await page.getByLabel("Word").fill("egg,egg"); + + await page.getByRole("button", { name: "Translate" }).click(); + + await expect( + page.getByTestId("translation-results").locator("li li") + ).toHaveText([ + /Ei/, + /Eier/, + /Eiweiß/, + /Eigelb/, + ]); +}); \ No newline at end of file