{"id":19692177,"url":"https://github.com/getgrav/grav-plugin-langswitcher","last_synced_at":"2025-04-29T09:31:23.639Z","repository":{"id":34790221,"uuid":"38774033","full_name":"getgrav/grav-plugin-langswitcher","owner":"getgrav","description":"Grav LangSwitcher Plugin","archived":false,"fork":false,"pushed_at":"2023-09-29T09:56:56.000Z","size":133,"stargazers_count":27,"open_issues_count":6,"forks_count":24,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-04-19T07:43:50.639Z","etag":null,"topics":["grav","grav-plugin","i18n","internationalization","multilanguage","multilingual"],"latest_commit_sha":null,"homepage":"https://getgrav.org","language":"PHP","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/getgrav.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2015-07-08T19:03:54.000Z","updated_at":"2025-03-15T20:58:00.000Z","dependencies_parsed_at":"2023-11-10T15:03:01.308Z","dependency_job_id":"59e5d9f5-7ffe-421c-a667-b3bf2556baed","html_url":"https://github.com/getgrav/grav-plugin-langswitcher","commit_stats":{"total_commits":64,"total_committers":10,"mean_commits":6.4,"dds":0.21875,"last_synced_commit":"042439babc6ed5dd6e514e145775d05033aca1cb"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getgrav%2Fgrav-plugin-langswitcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getgrav%2Fgrav-plugin-langswitcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getgrav%2Fgrav-plugin-langswitcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getgrav%2Fgrav-plugin-langswitcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getgrav","download_url":"https://codeload.github.com/getgrav/grav-plugin-langswitcher/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250380951,"owners_count":21421037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["grav","grav-plugin","i18n","internationalization","multilanguage","multilingual"],"created_at":"2024-11-11T19:12:31.214Z","updated_at":"2025-04-29T09:31:23.286Z","avatar_url":"https://github.com/getgrav.png","language":"PHP","readme":"# Grav LangSwitcher Plugin\n\n![LangSwitcher](assets/readme_1.png)\n\n`LangSwitcher` is a [Grav](http://github.com/getgrav/grav) plugin that provides native language text links to switch between [Multiple Languages](http://learn.getgrav.org/content/multi-language) in Grav **0.9.30** or greater.\n\n# Installation\n\nInstalling the LangSwitcher plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.\n\n## GPM Installation (Preferred)\n\nThe simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's Terminal (also called the command line).  From the root of your Grav install type:\n\n    bin/gpm install langswitcher\n\nThis will install the LangSwitcher plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/langswitcher`.\n\n## Manual Installation\n\nTo install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `langswitcher`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-langswitcher) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).\n\nYou should now have all the plugin files under\n\n    /your/site/grav/user/plugins/langswitcher\n\n# Usage\n\nThe `langswitcher` plugin doesn't require any configuration. You do however need to add the included Twig partials template into your own theme somewhere you want the available languages to be displayed.\n\n```twig\n{% include 'partials/langswitcher.html.twig' %}\n```\n\nSomething you might want to do is to override the look and feel of the langswitcher, and with Grav it is super easy.\n\nCopy the template file [langswitcher.html.twig](templates/partials/langswitcher.html.twig) into the `templates` folder of your custom theme:\n\n```\n/your/site/grav/user/themes/custom-theme/templates/partials/langswitcher.html.twig\n```\n\nYou can now edit the override and tweak it however you prefer.\n\n## Usage of the `hreflang` partial\n\nA second template is available for `hreflang` annotations in the header of the page. In order to emit language annotations for the available languages of a page you need to add the corrsponding Twig partial template into the `\u003chead\u003e` section of your page, which can typically be found in `base.html.twig`:\n\n```twkg\n{% include 'partials/langswitcher.hreflang.html.twig' %}\n```\n\nThis will generate something like:\n\n```html\n\u003clink rel=\"alternate\" href=\"http://example.com/en\" hreflang=\"en\" /\u003e\n\u003clink rel=\"alternate\" href=\"http://example.com/de\" hreflang=\"de\" /\u003e\n\u003clink rel=\"alternate\" href=\"http://example.com/zh-cn\" hreflang=\"zh-cn\" /\u003e\n```\n\n# Updating\n\nAs development for the LangSwitcher plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating LangSwitcher is easy, and can be done through Grav's GPM system, as well as manually.\n\n## GPM Update (Preferred)\n\nThe simplest way to update this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following:\n\n    bin/gpm update langswitcher\n\nThis command will check your Grav install to see if your LangSwitcher plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type `y` and hit enter. The plugin will automatically update and clear Grav's cache.\n\n\u003e Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in `user/config/plugins`) will remain intact.\n\n## Configuration\n\nSimply copy the `user/plugins/langswitcher/langswitcher.yaml` into `user/config/plugins/langswitcher.yaml` and make your modifications.\n\n```yaml\nenabled: true\nbuilt_in_css: true\ntranslated_urls: true\nuntranslated_pages_behavior: none\nlanguage_display: long\n```\n\nOptions are pretty self explanatory.\n\n## Redirecting after switching language\n\nTo have Grav redirect to the default page route after switching language, you must add the following configuration to `user/config/system.yaml`\n\n```yaml\npages:\n  redirect_default_route: true\n```\n\n## Customization\n\nThe default format for the displaying of the languages is to use the native language names in a **long** format (e.g. `English`, `Deutsch`, `Français`).  However, you can change the default output to use **short** names (e.g. `EN`, `DE`, `FR`).\n\nThis can be configured via the `langswitcher.yaml` configuration file:\n\n```yaml\nlanguage_display: long              # long | short are the valid options\n```\n\nYou can also pass the format in directly via the Twig include:\n\n```twig\n{% include 'partials/langswitcher.hreflang.html.twig' with {display_format: 'short'} %}\n```\n\nAlso you can override the two Twig partials that control the actual display of the **long** and **short** output, by copying the partial int your theme's `templates/partials/` folder and modifying:\n\n```twig\n# templates/partials/langswitcher-long.html.twig\n{{ native_name(language)|capitalize }}\n```\n\nand\n\n```twig\n# templates/partials/langswitcher-short.html.twig\n{{ language|upper }}\n```\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetgrav%2Fgrav-plugin-langswitcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetgrav%2Fgrav-plugin-langswitcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetgrav%2Fgrav-plugin-langswitcher/lists"}