{"id":20971808,"url":"https://github.com/separatrixxx/nextjs-localization","last_synced_at":"2026-02-10T17:03:39.203Z","repository":{"id":259076325,"uuid":"874702151","full_name":"separatrixxx/nextjs-localization","owner":"separatrixxx","description":"⚙️ Script for easy localization of applications on Next.js","archived":false,"fork":false,"pushed_at":"2024-10-23T14:48:31.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T16:44:00.531Z","etag":null,"topics":["i18n","localization","nextjs","react","router","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nextjs-localization","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/separatrixxx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-18T10:00:06.000Z","updated_at":"2024-10-23T14:48:53.000Z","dependencies_parsed_at":"2024-11-20T11:04:12.157Z","dependency_job_id":null,"html_url":"https://github.com/separatrixxx/nextjs-localization","commit_stats":null,"previous_names":["separatrixxx/nextjs-localization"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/separatrixxx/nextjs-localization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/separatrixxx%2Fnextjs-localization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/separatrixxx%2Fnextjs-localization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/separatrixxx%2Fnextjs-localization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/separatrixxx%2Fnextjs-localization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/separatrixxx","download_url":"https://codeload.github.com/separatrixxx/nextjs-localization/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/separatrixxx%2Fnextjs-localization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29308916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T16:09:25.305Z","status":"ssl_error","status_checked_at":"2026-02-10T16:08:52.170Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i18n","localization","nextjs","react","router","typescript"],"created_at":"2024-11-19T04:05:19.412Z","updated_at":"2026-02-10T17:03:39.164Z","avatar_url":"https://github.com/separatrixxx.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js Localization by separatrix\n\n**Next.js Localization** is a setup script and package to create a new Next.js project with built-in localization support. This setup includes a powerful context API for managing multiple locales and additional configurations to streamline development.\n\n## Usage\n\n### Step 1: Installation\n\nTo install the Next.js localization library, open your terminal and run one of the following commands:\n\n```bash\nnpm install -D nextjs-localization\n\n# or with yarn\n\nyarn add -D nextjs-localization\n```\n\n### Step 2: Configuration\n\nWrap your Next.js app with the `LocaleProvider` to manage locales throughout your application:\n\n```tsx\nimport { LocaleProvider } from 'nextjs-localization';\nimport { useRouter } from 'next/router';\nimport { en, ru } from '../locales';\n\nexport default function App({ Component, pageProps }) {\n  const router = useRouter();\n\n  return (\n    \u003cLocaleProvider localesArray={[en, ru]} router={router}\u003e\n      \u003cComponent {...pageProps} /\u003e\n    \u003c/LocaleProvider\u003e\n  );\n}\n```\n\n### Step 3: Import Functions\n\nYou can now import and use functions from `nextjs-localization` as needed.\n\n## Available Functions\n\n### `changeLocale(router: NextRouter, locale: string)`\n\nChanges the current locale and reloads the page with the new locale.\n\n```tsx\nimport { changeLocale } from 'nextjs-localization';\nimport { useRouter } from 'next/router';\n\nconst router = useRouter();\nchangeLocale(router, 'ru'); // Switches the locale to Russian\n```\n\n### `setLocale(key: string, value?: string): string`\n\nFetches the localized string based on the current locale and replaces a placeholder `$$$` with a provided value (if any).\n\n```tsx\nimport { setLocale } from 'nextjs-localization';\n\nconst message = setLocale('welcome_message', 'user'); // Returns \"Welcome, user\" in the current locale\n\n\u003ch1\u003e{message}\u003c/h1\u003e // Displays: Welcome, user\n```\n\n### `getCurrentLocale(): string`\n\nFetches the current locale from the router or returns the default locale ('en').\n\n```tsx\nimport { getCurrentLocale } from 'nextjs-localization';\n\nconst currentLocale = getCurrentLocale(); // Returns the current locale (default is 'en')\n```\n\n### `getAvailableLocales(): string[]`\n\nGets a list of all available locales in the current context.\n\n```tsx\nimport { getAvailableLocales } from 'nextjs-localization';\n\nconst availableLocales = getAvailableLocales(); // Returns an array of all available locale codes\n```\n\n### `getAllGlobalLocales(): GlobalLocale[]`\n\nGets a list of all global locales with their codes, languages, countries, and flags.\n\n```tsx\nimport { getAllGlobalLocales } from 'nextjs-localization';\n\nconst allLocales = getAllGlobalLocales(); // Returns an array of GlobalLocale objects\n```\n\n### `getLocaleData(locale: string): GlobalLocale | undefined`\n\nFetches detailed information for a specific locale by its code.\n\n```tsx\nimport { getLocaleData } from 'nextjs-localization';\n\nconst localeData = getLocaleData('en_US'); // Returns GlobalLocale object for 'en_US' or undefined if not found\n\nconsole.log(localeData?.country); // Output: [\"United States\"]\n```\n\n## Localization Files\n\nIt is recommended to create JSON or TypeScript files for each locale (e.g., `en.ts`, `ru.ts`) in the `locales` folder. Here is an example:\n\n```ts\n// locales/en.ts\nexport const en = {\n  locale: \"en\",\n  language: \"English\",\n  welcome_message: \"Welcome to our website\",\n  error404: \"Page not found, 404 error\",\n};\n\n// locales/ru.ts\nexport const ru = {\n  locale: \"ru\",\n  language: \"Русский\",\n  welcome_message: \"Добро пожаловать на наш сайт\",\n  error404: \"Страница не найдена, ошибка 404\",\n};\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseparatrixxx%2Fnextjs-localization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseparatrixxx%2Fnextjs-localization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseparatrixxx%2Fnextjs-localization/lists"}