Enhance site with bilingual support

Added conditions for changing form labels, navigation items according to the current locale. The README file was also updated accordingly to reflect these changes.
This commit is contained in:
Emil Gulamov 2024-03-26 09:11:14 +04:00
parent 7700a60c9e
commit 9caf68d975
11 changed files with 30 additions and 18 deletions

View file

@ -172,6 +172,7 @@ src/
├── pages/ # Astro files representing individual pages and website sections ├── pages/ # Astro files representing individual pages and website sections
│ ├── 404.astro # Custom 404 page │ ├── 404.astro # Custom 404 page
│ ├── blog/ │ ├── blog/
│ ├── fr/ # Localized content
│ ├── contact.astro │ ├── contact.astro
│ ├── index.astro # The landing/home page │ ├── index.astro # The landing/home page
│ ├── insights/ │ ├── insights/
@ -329,7 +330,7 @@ export const socialLinks: SocialLinks = {
> [!NOTE] > [!NOTE]
> Remember to add complete and valid URLs for the navigation to function properly. These customizations will reflect throughout your Astro site, promoting consistency across all pages. > Remember to add complete and valid URLs for the navigation to function properly. These customizations will reflect throughout your Astro site, promoting consistency across all pages.
</details>
## Integrations and Enhancements ## Integrations and Enhancements
@ -374,18 +375,22 @@ Here's how we set up Lenis in `src/layouts/MainLayout.astro`:
requestAnimationFrame(raf); // Start the loop requestAnimationFrame(raf); // Start the loop
</script> </script>
<style> <style>
html.lenis { html.lenis, html.lenis body {
height: auto; height: auto;
} }
.lenis.lenis-smooth { .lenis.lenis-smooth {
scroll-behavior: auto !important; scroll-behavior: auto !important;
} }
.lenis.lenis-smooth [data-lenis-prevent] { .lenis.lenis-smooth [data-lenis-prevent] {
overscroll-behavior: contain; overscroll-behavior: contain;
} }
.lenis.lenis-stopped { .lenis.lenis-stopped {
overflow: hidden; overflow: hidden;
} }
.lenis.lenis-scrolling iframe { .lenis.lenis-scrolling iframe {
pointer-events: none; pointer-events: none;
} }
@ -578,7 +583,6 @@ Configure the compressor in `astro.config.mjs` file:
### Flexibility with Integrations ### Flexibility with Integrations
The great thing about Astro is its rich ecosystem of integrations, allowing you to tailor project functionalities to your exact needs. Feel free to explore [Astro integrations page](https://astro.build/integrations/) and add additional capabilities as you see fit. The great thing about Astro is its rich ecosystem of integrations, allowing you to tailor project functionalities to your exact needs. Feel free to explore [Astro integrations page](https://astro.build/integrations/) and add additional capabilities as you see fit.
</details>
## Tools and Technologies ## Tools and Technologies

View file

@ -15,6 +15,9 @@ export default defineConfig({
i18n: { i18n: {
defaultLocale: "en", defaultLocale: "en",
locales: ["en", "fr"], locales: ["en", "fr"],
fallback: {
fr: "en"
},
routing: { routing: {
prefixDefaultLocale: false prefixDefaultLocale: false
} }

View file

@ -5,6 +5,8 @@ import GithubBtn from "../../ui/buttons/GithubBtn.astro";
// Define props from Astro // Define props from Astro
const { title, subTitle, url } = Astro.props; const { title, subTitle, url } = Astro.props;
const btnTitle = Astro.currentLocale === "fr" ? "Continuer avec Github" : "Continue with Github";
// Define TypeScript interface for props // Define TypeScript interface for props
interface Props { interface Props {
title: string; title: string;
@ -136,7 +138,7 @@ interface Props {
{ {
url && ( url && (
<div class="mt-8 flex justify-center gap-3"> <div class="mt-8 flex justify-center gap-3">
<GithubBtn url={url} /> <GithubBtn url={url} title={btnTitle}/>
</div> </div>
) )
} }

View file

@ -1,6 +1,6 @@
--- ---
import Icon from "../icons/Icon.astro"; import Icon from "../icons/Icon.astro";
const { title = "Continue with Github", url } = Astro.props; const { title, url } = Astro.props;
interface Props { interface Props {
title?: string; title?: string;

View file

@ -1,5 +1,5 @@
--- ---
const { label = "Remember me", id } = Astro.props; const { label = Astro.currentLocale === "fr" ? "Me rappeler" : "Remember me", id } = Astro.props;
interface Props { interface Props {
label?: string; label?: string;

View file

@ -1,5 +1,5 @@
--- ---
const { label = "Email", id } = Astro.props; const { label = Astro.currentLocale === "fr" ? "E-mail" : "Email", id } = Astro.props;
interface Props { interface Props {
label?: string; label?: string;

View file

@ -1,7 +1,7 @@
--- ---
const { const {
label = "Search", label = "Search",
title = "Subscribe", title = Astro.currentLocale === "fr" ? "S'abonner" : "Subscribe",
id = "footer-input", id = "footer-input",
} = Astro.props; } = Astro.props;
@ -10,6 +10,8 @@ interface Props {
title?: string; title?: string;
id?: string; id?: string;
} }
const placeholder = Astro.currentLocale === "fr" ? "Entrez votre email" : "Enter your email";
--- ---
<div <div
@ -22,7 +24,7 @@ interface Props {
id={id} id={id}
name="footer-input" name="footer-input"
class="block w-full rounded-lg border-transparent bg-neutral-100 px-4 py-3 text-sm text-neutral-600 focus:border-[#fa5a15] focus:ring-[#fa5a15] disabled:pointer-events-none disabled:opacity-50 dark:border-transparent dark:bg-neutral-700 dark:text-gray-300 dark:placeholder:text-neutral-300" class="block w-full rounded-lg border-transparent bg-neutral-100 px-4 py-3 text-sm text-neutral-600 focus:border-[#fa5a15] focus:ring-[#fa5a15] disabled:pointer-events-none disabled:opacity-50 dark:border-transparent dark:bg-neutral-700 dark:text-gray-300 dark:placeholder:text-neutral-300"
placeholder="Enter your email" placeholder={placeholder}
/> />
</div> </div>
<a <a

View file

@ -1,5 +1,5 @@
--- ---
const { label = "Email address", id, errorId } = Astro.props; const { label = Astro.currentLocale === "fr" ? "Adresse e-mail" : "Email address", id, errorId } = Astro.props;
interface Props { interface Props {
label?: string; label?: string;

View file

@ -1,5 +1,5 @@
--- ---
const { label = "Phone Number", id } = Astro.props; const { label= Astro.currentLocale === "fr" ? "Numéro de téléphone" : "Phone Number", id } = Astro.props;
interface Props { interface Props {
label?: string; label?: string;

View file

@ -27,8 +27,9 @@ If URL is '/' (home page), assign ID as 'home'
<script> <script>
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
let url = window.location.pathname; let url = window.location.pathname;
let firstPathSegment = url.split("/")[1]; let urlSegments = url.split("/");
let navId = firstPathSegment ? firstPathSegment : "home"; let navId = urlSegments[1] === 'fr' ? urlSegments[2] : urlSegments[1];
navId = navId ? navId : 'home';
let nav = document.getElementById(navId); let nav = document.getElementById(navId);
if (nav) { if (nav) {
nav.classList.remove( nav.classList.remove(

View file

@ -2,21 +2,21 @@
{ {
"heading": "Équipes dédiées", "heading": "Équipes dédiées",
"content": "Bénéficiez de nos équipes engagées qui veillent à ce que votre réussite soit personnelle. Comptez sur un accompagnement expert et des résultats exceptionnels tout au long de votre parcours de projet.", "content": "Bénéficiez de nos équipes engagées qui veillent à ce que votre réussite soit personnelle. Comptez sur un accompagnement expert et des résultats exceptionnels tout au long de votre parcours de projet.",
"svg": "groupes" "svg": "groups"
}, },
{ {
"heading": "Simplicité et accessibilité", "heading": "Simplicité et accessibilité",
"content": "Trouvez des solutions faciles à utiliser et abordables avec la gamme d'outils et d'équipements de ScrewFast. Nos produits simplifient l'approvisionnement et permettent de respecter les budgets de projet.", "content": "Trouvez des solutions faciles à utiliser et abordables avec la gamme d'outils et d'équipements de ScrewFast. Nos produits simplifient l'approvisionnement et permettent de respecter les budgets de projet.",
"svg": "vérifié" "svg": "verified"
}, },
{ {
"heading": "Documentation complète", "heading": "Documentation complète",
"content": "Intégrez facilement grâce aux guides exhaustifs et aux bibliothèques de ScrewFast. Réalisez une adoption de produit sans faille avec notre ensemble complet de documentation conçu pour votre succès.", "content": "Intégrez facilement grâce aux guides exhaustifs et aux bibliothèques de ScrewFast. Réalisez une adoption de produit sans faille avec notre ensemble complet de documentation conçu pour votre succès.",
"svg": "livres" "svg": "books"
}, },
{ {
"heading": "Conception centrée sur l'utilisateur", "heading": "Conception centrée sur l'utilisateur",
"content": "Faites l'expérience de la différence avec la conception axée sur l'utilisateur de ScrewFast, où la fonctionnalité rencontre la praticité pour une expérience de travail améliorée.", "content": "Faites l'expérience de la différence avec la conception axée sur l'utilisateur de ScrewFast, où la fonctionnalité rencontre la praticité pour une expérience de travail améliorée.",
"svg": "cadre" "svg": "frame"
} }
] ]