├── CHANGELOG.md ├── LICENSE ├── README.md ├── assets └── readme_1.jpg ├── blueprints.yaml ├── css └── language-selector.css ├── flags ├── af.png ├── ar.png ├── be.png ├── bg.png ├── bo.png ├── ca.png ├── cs.png ├── da.png ├── de.png ├── el.png ├── en.png ├── eo.png ├── es.png ├── et.png ├── eu.png ├── fa.png ├── fi.png ├── fil.png ├── fo.png ├── fr.png ├── ga.png ├── gl.png ├── he.png ├── hi.png ├── hr.png ├── hu.png ├── id.png ├── is.png ├── it.png ├── ja.png ├── km.png ├── ko.png ├── lb.png ├── lt.png ├── lv.png ├── mn.png ├── ms.png ├── nb.png ├── nl.png ├── nn.png ├── pl.png ├── pt-br.png ├── pt-pt.png ├── ro.png ├── ru.png ├── sco.png ├── se.png ├── sk.png ├── sl.png ├── so.png ├── sq.png ├── sr.png ├── sv.png ├── tg.png ├── th.png ├── tl.png ├── tr.png ├── uk.png ├── vi.png ├── zh-hans.png └── zh-hant.png ├── js └── language-selector.js ├── language-selector.php ├── language-selector.yaml ├── languages.yaml └── templates └── partials ├── language-selector.hreflang.html.twig └── language-selector.html.twig /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # v1.1.0 3 | ## 11/23/2018 4 | 5 | 1. [](#improved) 6 | * Add pull-request [#7](https://github.com/clemdesign/grav-plugin-language-selector/pull/7): Need jQuery 1.8 or later. 7 | 8 | 9 | # v1.0.1 10 | ## 08/10/2018 11 | 12 | 1. [](#improved) 13 | * Add pull-request [#1](https://github.com/clemdesign/grav-plugin-language-selector/pull/1) 14 | 15 | 2. [](#bugfix) 16 | * Fix issue [#2](https://github.com/clemdesign/grav-plugin-language-selector/issues/2) 17 | -> Improve jQuery integration 18 | 19 | # v1.0.0 20 | ## 07/22/2017 21 | 22 | 1. [](#new) 23 | * ChangeLog started... 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Clemdesign (http://www.clemdesign.fr) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Grav Language Selector Plugin 2 | 3 | ![Language Selector](assets/readme_1.jpg) 4 | 5 | `Language Selector` is a [Grav](http://github.com/getgrav/grav) plugin that provides native language selector with flags to switch between [Multiple Languages](http://learn.getgrav.org/content/multi-language). 6 | 7 | # Installation 8 | 9 | Installing the Language Selector plugin can be done in one of two ways. 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 or GIT. 10 | 11 | ## GPM Installation (Preferred) 12 | 13 | The 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: 14 | 15 | bin/gpm install language-selector 16 | 17 | This will install the Language Selector plugin into your `/user/plugins` directory within Grav. Its files can be found under `/yoursite/user/plugins/language-selector`. 18 | 19 | ## Manual Installation (Download) 20 | 21 | To install this plugin, just download the zip version of this repository and unzip it under `user/plugins`. Then, rename the folder to `language-selector`. You can find these files either on [GitHub](https://github.com/clemdesign/grav-plugin-language-selector). 22 | 23 | You should now have all the plugin files under 24 | 25 | /yoursite/user/plugins/language-selector 26 | 27 | 28 | ## Manual Installation (Using GIT) 29 | 30 | In `user/plugins` folder, apply the following command: 31 | ``` 32 | git clone https://github.com/clemdesign/grav-plugin-language-selector language-selector 33 | ``` 34 | 35 | This will clone this repository into the _language-selector_ folder. 36 | 37 | # Usage 38 | 39 | ## 1. Define the supported languages 40 | 41 | In `system.yaml`, add the supported languages in `languages.supported` parameter. 42 | 43 | Example: 44 | 45 | languages: 46 | supported: 47 | - fr 48 | - en 49 | 50 | ## 2. Integration 51 | 52 | You do need to add the included Twig partials template into your own theme somewhere you want the available languages to be displayed. 53 | 54 | ``` 55 | {% include 'partials/language-selector.html.twig' %} 56 | ``` 57 | 58 | Something you might want to do is to override the look and feel of the langswitcher, and with Grav it is super easy. 59 | 60 | Copy the template file [language-selector.html.twig](templates/partials/language-selector.html.twig) into the `templates` folder of your custom theme: 61 | 62 | ``` 63 | /yoursite/user/themes/custom-theme/templates/partials/language-selector.html.twig 64 | ``` 65 | 66 | You can now edit the override and tweak it however you prefer. 67 | 68 | `language-selector` need jQuery (1.8 -> later) to display dropdown language menu. 69 | 70 | ## 3. Usage of the `hreflang` partial 71 | 72 | A 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 `` section of your page, which can typically be found in `base.html.twig`: 73 | 74 | ``` 75 | {% include 'partials/language-selector.hreflang.html.twig' %} 76 | ``` 77 | 78 | This will generate something like: 79 | 80 | ``` 81 | 82 | 83 | 84 | ``` 85 | 86 | # Configuration 87 | 88 | ## Plugin 89 | 90 | Simply copy the `user/plugins/language-selector/language-selector.yaml` into `user/config/plugins/language-selector.yaml` and make your modifications. 91 | 92 | ``` 93 | enabled: true 94 | built_in_css: true 95 | button_display: default 96 | select_display: default 97 | ``` 98 | 99 | Options `enabled` and `built_in_css` are pretty self explanatory. 100 | 101 | For `button_display`, this one define how button of selected language will be displayed. There are 3 possibilities: 102 | - `default`: Flag and Language name are displayed 103 | - `flag`: Only flag is displayed 104 | - `name`: Only language name is displayed 105 | 106 | For `select_display`, this one define how language selector will be displayed. There are 3 possibilities: 107 | - `default`: Flag and Language name are displayed 108 | - `flag`: Only flag is displayed 109 | - `name`: Only language name is displayed 110 | 111 | ## Redirecting after switching language 112 | 113 | To have Grav redirect to the default page route after switching language, you must add the following configuration to `user/config/system.yaml` 114 | ``` 115 | pages: 116 | redirect_default_route: true 117 | ``` 118 | 119 | # Contribute 120 | 121 | ## Languages 122 | 123 | For Administration panel, `Language Selector` is available in English and French. You could contribute for another languages. 124 | 125 | For flags and language names, it is available for both match between flag images (content in `language-selector/flags`) and the list of language name in `Grav/Common/Language/LanguageCodes.php`. 126 | You could contribute by adding new flags to match with list of language name, or the opposite. 127 | 128 | Flag images are sized 24 x 12 pixels in PNG. 129 | 130 | 131 | 132 | # Credits 133 | 134 | [Language Selector](https://github.com/clemdesign/grav-plugin-language-selector) is based on [Lang Switcher](https://github.com/getgrav/grav-plugin-langswitcher) plugin. 135 | -------------------------------------------------------------------------------- /assets/readme_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/assets/readme_1.jpg -------------------------------------------------------------------------------- /blueprints.yaml: -------------------------------------------------------------------------------- 1 | name: Language Selector 2 | version: 1.1.0 3 | description: Language Selector is a [Grav](http://github.com/getgrav/grav) plugin that provides native language selector with flags to switch between [multiple languages](http://learn.getgrav.org/content/multi-language). 4 | icon: globe 5 | author: 6 | name: Clément G. 7 | email: contact@clemdesign.fr 8 | url: http://www.clemdesign.fr 9 | homepage: https://github.com/clemdesign/grav-plugin-language-selector 10 | keywords: mulitlang, multilanguage, translation, switcher, selector, flag 11 | bugs: https://github.com/clemdesign/grav-plugin-language-selector/issues 12 | docs: https://github.com/clemdesign/grav-plugin-language-selector/blob/master/README.md 13 | license: MIT 14 | 15 | form: 16 | validation: strict 17 | fields: 18 | enabled: 19 | type: toggle 20 | label: PLUGINS.LANGUAGE_SELECTOR.PLUGIN_STATUS 21 | highlight: 1 22 | default: 1 23 | options: 24 | 1: PLUGIN_ADMIN.ENABLED 25 | 0: PLUGIN_ADMIN.DISABLED 26 | validate: 27 | type: bool 28 | 29 | built_in_css: 30 | type: toggle 31 | label: PLUGINS.LANGUAGE_SELECTOR.BUILT_IN_CSS 32 | highlight: 1 33 | default: 1 34 | options: 35 | 1: PLUGIN_ADMIN.ENABLED 36 | 0: PLUGIN_ADMIN.DISABLED 37 | validate: 38 | type: bool 39 | 40 | untranslated_pages_behavior: 41 | type: select 42 | label: PLUGINS.LANGUAGE_SELECTOR.UNTRANSLATED_PAGES.LABEL 43 | help: PLUGINS.LANGUAGE_SELECTOR.UNTRANSLATED_PAGES.HELP 44 | default: none 45 | options: 46 | none: PLUGINS.LANGUAGE_SELECTOR.UNTRANSLATED_PAGES.OPT_NONE 47 | redirect: PLUGINS.LANGUAGE_SELECTOR.UNTRANSLATED_PAGES.OPT_REDIR 48 | hide: PLUGINS.LANGUAGE_SELECTOR.UNTRANSLATED_PAGES.OPT_HIDE 49 | 50 | button_display: 51 | type: select 52 | label: PLUGINS.LANGUAGE_SELECTOR.BUTTON_DISPLAY.LABEL 53 | help: PLUGINS.LANGUAGE_SELECTOR.BUTTON_DISPLAY.HELP 54 | default: default 55 | options: 56 | default: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.OPT_DEFAULT 57 | flag: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.OPT_FLAG 58 | name: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.OPT_NAME 59 | 60 | select_display: 61 | type: select 62 | label: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.LABEL 63 | help: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.HELP 64 | default: default 65 | options: 66 | default: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.OPT_DEFAULT 67 | flag: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.OPT_FLAG 68 | name: PLUGINS.LANGUAGE_SELECTOR.SELECT_DISPLAY.OPT_NAME 69 | -------------------------------------------------------------------------------- /css/language-selector.css: -------------------------------------------------------------------------------- 1 | .language-selector { 2 | float: right; 3 | position: relative; 4 | top: 50%; 5 | vertical-align: middle; 6 | -webkit-transform: translateY(-50%); 7 | -moz-transform: translateY(-50%); 8 | -o-transform: translateY(-50%); 9 | -ms-transform: translateY(-50%); 10 | transform: translateY(-50%); 11 | margin: 0 1rem !important; 12 | display: inline-block; 13 | } 14 | 15 | .language-selector>.btn:first-child { 16 | margin-left: 0; 17 | } 18 | 19 | .language-selector .btn { 20 | float: left; 21 | position: relative; 22 | display: inline-block; 23 | margin-bottom: 0; 24 | font-weight: 400; 25 | text-align: center; 26 | white-space: nowrap; 27 | vertical-align: middle; 28 | touch-action: manipulation; 29 | cursor: pointer; 30 | user-select: none; 31 | background-image: none; 32 | border: 1px solid transparent; 33 | /* size */ 34 | padding: 5px 10px; 35 | font-size: 0.8rem; 36 | line-height: 1.5; 37 | border-radius: 3px; 38 | /* Aspect */ 39 | color: #333; 40 | background-color: #fff; 41 | border-color: #ccc; 42 | } 43 | 44 | .language-selector .dropdown-menu { 45 | position: absolute; 46 | top: 100%; 47 | left: 0; 48 | z-index: 1000; 49 | display: none; 50 | float: left; 51 | padding: 5px 0; 52 | margin: 2px 0 0; 53 | font-size: 1rem; 54 | text-align: left; 55 | list-style: none; 56 | background-color: #fff; 57 | background-clip: padding-box; 58 | border-radius: 4px; 59 | box-shadow: 0 6px 12px rgba(0,0,0,.175); 60 | } 61 | 62 | .language-selector .dropdown-menu img { 63 | width: 24px; 64 | height: 12px; 65 | max-width: inherit; 66 | } 67 | 68 | .language-selector .dropdown-menu li { 69 | line-height: 1rem; 70 | font-color: #c0c0c0; 71 | display: list-item; 72 | text-align: -webkit-match-parent; 73 | } 74 | 75 | .language-selector .dropdown-menu li:hover { 76 | background-color: #eee; 77 | } 78 | 79 | .language-selector .dropdown-menu>li>a { 80 | display: block; 81 | padding: 3px 15px; 82 | clear: both; 83 | font-weight: 400; 84 | line-height: 1.42857143; 85 | color: #333; 86 | white-space: nowrap; 87 | } 88 | -------------------------------------------------------------------------------- /flags/af.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/af.png -------------------------------------------------------------------------------- /flags/ar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ar.png -------------------------------------------------------------------------------- /flags/be.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/be.png -------------------------------------------------------------------------------- /flags/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/bg.png -------------------------------------------------------------------------------- /flags/bo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/bo.png -------------------------------------------------------------------------------- /flags/ca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ca.png -------------------------------------------------------------------------------- /flags/cs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/cs.png -------------------------------------------------------------------------------- /flags/da.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/da.png -------------------------------------------------------------------------------- /flags/de.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/de.png -------------------------------------------------------------------------------- /flags/el.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/el.png -------------------------------------------------------------------------------- /flags/en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/en.png -------------------------------------------------------------------------------- /flags/eo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/eo.png -------------------------------------------------------------------------------- /flags/es.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/es.png -------------------------------------------------------------------------------- /flags/et.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/et.png -------------------------------------------------------------------------------- /flags/eu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/eu.png -------------------------------------------------------------------------------- /flags/fa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/fa.png -------------------------------------------------------------------------------- /flags/fi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/fi.png -------------------------------------------------------------------------------- /flags/fil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/fil.png -------------------------------------------------------------------------------- /flags/fo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/fo.png -------------------------------------------------------------------------------- /flags/fr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/fr.png -------------------------------------------------------------------------------- /flags/ga.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ga.png -------------------------------------------------------------------------------- /flags/gl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/gl.png -------------------------------------------------------------------------------- /flags/he.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/he.png -------------------------------------------------------------------------------- /flags/hi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/hi.png -------------------------------------------------------------------------------- /flags/hr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/hr.png -------------------------------------------------------------------------------- /flags/hu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/hu.png -------------------------------------------------------------------------------- /flags/id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/id.png -------------------------------------------------------------------------------- /flags/is.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/is.png -------------------------------------------------------------------------------- /flags/it.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/it.png -------------------------------------------------------------------------------- /flags/ja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ja.png -------------------------------------------------------------------------------- /flags/km.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/km.png -------------------------------------------------------------------------------- /flags/ko.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ko.png -------------------------------------------------------------------------------- /flags/lb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/lb.png -------------------------------------------------------------------------------- /flags/lt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/lt.png -------------------------------------------------------------------------------- /flags/lv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/lv.png -------------------------------------------------------------------------------- /flags/mn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/mn.png -------------------------------------------------------------------------------- /flags/ms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ms.png -------------------------------------------------------------------------------- /flags/nb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/nb.png -------------------------------------------------------------------------------- /flags/nl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/nl.png -------------------------------------------------------------------------------- /flags/nn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/nn.png -------------------------------------------------------------------------------- /flags/pl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/pl.png -------------------------------------------------------------------------------- /flags/pt-br.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/pt-br.png -------------------------------------------------------------------------------- /flags/pt-pt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/pt-pt.png -------------------------------------------------------------------------------- /flags/ro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ro.png -------------------------------------------------------------------------------- /flags/ru.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/ru.png -------------------------------------------------------------------------------- /flags/sco.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/sco.png -------------------------------------------------------------------------------- /flags/se.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/se.png -------------------------------------------------------------------------------- /flags/sk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/sk.png -------------------------------------------------------------------------------- /flags/sl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/sl.png -------------------------------------------------------------------------------- /flags/so.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/so.png -------------------------------------------------------------------------------- /flags/sq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/sq.png -------------------------------------------------------------------------------- /flags/sr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/sr.png -------------------------------------------------------------------------------- /flags/sv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/sv.png -------------------------------------------------------------------------------- /flags/tg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/tg.png -------------------------------------------------------------------------------- /flags/th.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/th.png -------------------------------------------------------------------------------- /flags/tl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/tl.png -------------------------------------------------------------------------------- /flags/tr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/tr.png -------------------------------------------------------------------------------- /flags/uk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/uk.png -------------------------------------------------------------------------------- /flags/vi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/vi.png -------------------------------------------------------------------------------- /flags/zh-hans.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/zh-hans.png -------------------------------------------------------------------------------- /flags/zh-hant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clemdesign/grav-plugin-language-selector/3283b49f66a6e443d0a142cfe79fd38d9923c11d/flags/zh-hant.png -------------------------------------------------------------------------------- /js/language-selector.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Language Selector JS plugin 3 | * Copyright 2017 Clement G., Inc. 4 | * Licensed under MIT 5 | */ 6 | 7 | var dropdownmenu={ 8 | animspeed: 200, //reveal animation speed (in milliseconds) 9 | showhidedelay: [150, 150], //delay before menu appears and disappears when mouse rolls over it, in milliseconds 10 | 11 | //***** NO NEED TO EDIT BEYOND HERE 12 | builtdropdownids: [], //ids of dropdown already built (to prevent repeated building of same dropdown) 13 | stubboxenable: false, 14 | 15 | showbox:function($, $dropdown){ 16 | this.stubboxenable = false; 17 | clearTimeout($dropdown.data('timers').hidetimer); 18 | $dropdown.data('timers').showtimer=setTimeout(function(){$dropdown.show(dropdownmenu.animspeed)}, this.showhidedelay[0]) 19 | }, 20 | 21 | hidebox:function($, $dropdown){ 22 | if(this.stubboxenable === false) { 23 | clearTimeout($dropdown.data('timers').showtimer); 24 | $dropdown.data('timers').hidetimer=setTimeout(function(){$dropdown.hide(100)}, this.showhidedelay[1]) //hide dropdown plus all of its sub ULs 25 | } 26 | }, 27 | 28 | stubbox:function($, $dropdown){ 29 | this.stubboxenable = true; 30 | clearTimeout($dropdown.data('timers').hidetimer); 31 | $dropdown.data('timers').showtimer=setTimeout(function(){$dropdown.show(dropdownmenu.animspeed)}, this.showhidedelay[0]) 32 | }, 33 | 34 | 35 | builddropdown:function($, $menu, $target){ 36 | $menu.css({display:'none'}).addClass('jqdropdown'); 37 | $menu.bind('mouseenter', function(){ 38 | clearTimeout($menu.data('timers').hidetimer) 39 | }); 40 | $menu.bind('mouseleave', function(){ //hide menu when mouse moves out of it 41 | dropdownmenu.hidebox($, $menu) 42 | }); 43 | $menu.data('dimensions', {w:$menu.outerWidth(), h:$menu.outerHeight()}); //remember main menu's dimensions 44 | $menu.data('timers', {}); 45 | this.builtdropdownids.push($menu.get(0).id) //remember id of dropdown that was just built 46 | }, 47 | 48 | 49 | 50 | init:function($, $target, $dropdown){ 51 | if (this.builtdropdownids.length === 0){ //only bind click event to document once 52 | $(document).bind("click", function(e){ 53 | if (e.button === 0){ //hide all dropdown (and their sub ULs) when left mouse button is clicked 54 | $('.jqdropdown').find('ul').addBack().hide() 55 | } 56 | }) 57 | } 58 | if (jQuery.inArray($dropdown.get(0).id, this.builtdropdownids) === -1) //if this dropdown hasn't been built yet 59 | this.builddropdown($, $dropdown, $target); 60 | if ($target.parents().filter('ul.jqdropdown').length>0) //if $target matches an element within the dropdown markup, don't bind ondropdown to that element 61 | return; 62 | $target.bind("mouseenter", function(e){ 63 | dropdownmenu.showbox($, $dropdown) 64 | }); 65 | $target.bind("mouseleave", function(e){ 66 | dropdownmenu.hidebox($, $dropdown) 67 | }); 68 | $target.bind("click", function(e){ 69 | dropdownmenu.stubbox($, $dropdown) 70 | }) 71 | } 72 | }; 73 | 74 | //By default, add dropdown to anchor links with attribute "data-dropdown" 75 | jQuery(document).ready(function($){ 76 | 77 | jQuery.fn.adddropdown=function(dropdownid){ 78 | var $=jQuery; 79 | return this.each(function(){ //return jQuery obj 80 | var $target=$(this); 81 | var $dropdownId = $('#'+dropdownid); 82 | if ($dropdownId.length === 1) //check dropdown is defined 83 | dropdownmenu.init($, $target, $dropdownId) 84 | }) 85 | }; 86 | 87 | var $anchors=$('*[data-dropdown]'); 88 | $anchors.each(function(){ 89 | $(this).adddropdown(this.getAttribute('data-dropdown')) 90 | }) 91 | }); 92 | -------------------------------------------------------------------------------- /language-selector.php: -------------------------------------------------------------------------------- 1 | ['onPluginsInitialized', 0] 17 | ]; 18 | } 19 | 20 | /** 21 | * Initialize configuration 22 | */ 23 | public function onPluginsInitialized() 24 | { 25 | if ($this->isAdmin()) { 26 | $this->active = false; 27 | return; 28 | } 29 | 30 | $this->enable([ 31 | 'onTwigInitialized' => ['onTwigInitialized', 0], 32 | 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], 33 | 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] 34 | ]); 35 | } 36 | 37 | /** Add the native_name function */ 38 | public function onTwigInitialized() 39 | { 40 | $this->grav['twig']->twig()->addFunction( 41 | new \Twig_SimpleFunction('native_name', function($key) { 42 | return LanguageCodes::getNativeName($key); 43 | }) 44 | ); 45 | } 46 | 47 | /** 48 | * Add current directory to twig lookup paths. 49 | */ 50 | public function onTwigTemplatePaths() 51 | { 52 | $this->grav['twig']->twig_paths[] = __DIR__ . '/templates'; 53 | } 54 | 55 | /** 56 | * Set needed variables to display Language-Selector. 57 | */ 58 | public function onTwigSiteVariables() 59 | { 60 | $data = new \stdClass; 61 | 62 | // Manage Data content 63 | $page = $this->grav['page']; 64 | $data->page_route = $page->rawRoute(); 65 | if ($page->home()) { 66 | $data->page_route = '/'; 67 | } 68 | 69 | $languages = $this->grav['language']->getLanguages(); 70 | $data->languages = $languages; 71 | 72 | if ($this->config->get('plugins.language-selector.untranslated_pages_behavior') !== 'none') { 73 | $translated_pages = []; 74 | foreach ($languages as $language) { 75 | $translated_pages[$language] = null; 76 | $page_name_without_ext = substr($page->name(), 0, -(strlen($page->extension()))); 77 | $translated_page_path = $page->path() . DS . $page_name_without_ext . '.' . $language . '.md'; 78 | if (file_exists($translated_page_path)) { 79 | $translated_page = new Page(); 80 | $translated_page->init(new \SplFileInfo($translated_page_path), $language . '.md'); 81 | $translated_pages[$language] = $translated_page; 82 | } 83 | } 84 | $data->translated_pages = $translated_pages; 85 | } 86 | 87 | $data->current = $this->grav['language']->getLanguage(); 88 | 89 | // Manage Twig Variables 90 | $path_flags = $this->grav['locator']->findResource('plugin://language-selector/flags/', false) . "/"; 91 | $path_flags = $this->grav['base_url'] ."/". ltrim($path_flags, '/'); 92 | $this->grav['twig']->twig_vars['language_selector'] = $data; 93 | $this->grav['twig']->twig_vars['language_display'] = array( 94 | "select" => $this->config->get('plugins.language-selector.select_display'), 95 | "button" => $this->config->get('plugins.language-selector.button_display'), 96 | ); 97 | $this->grav['twig']->twig_vars['path_flags'] = $path_flags; 98 | 99 | // Manage Assets 100 | $this->grav['assets']->add('plugin://language-selector/js/language-selector.js'); 101 | if ($this->config->get('plugins.language-selector.built_in_css')) { 102 | $this->grav['assets']->add('plugin://language-selector/css/language-selector.css'); 103 | } 104 | } 105 | 106 | public function getNativeName($code) { 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /language-selector.yaml: -------------------------------------------------------------------------------- 1 | enabled: true 2 | built_in_css: true 3 | untranslated_pages_behavior: none 4 | button_display: default 5 | select_display: default 6 | -------------------------------------------------------------------------------- /languages.yaml: -------------------------------------------------------------------------------- 1 | # English 2 | en: 3 | PLUGINS: 4 | LANGUAGE_SELECTOR: 5 | PLUGIN_STATUS: 'Plugin status' 6 | BUILT_IN_CSS: 'Use built in CSS' 7 | UNTRANSLATED_PAGES: 8 | LABEL: 'Untranslated pages behavior' 9 | HELP: 'Determine what to do with a language link when the current page doesn''t exist in that language or it exists but it''s not published.' 10 | OPT_NONE: 'Show language (default)' 11 | OPT_REDIR: 'Show language, link to home route' 12 | OPT_HIDE: 'Hide language' 13 | BUTTON_DISPLAY: 14 | LABEL: 'Button Display' 15 | HELP: 'Define how button of selected language will be displayed' 16 | SELECT_DISPLAY: 17 | LABEL: 'Selector Display' 18 | HELP: 'Define how language selector will be displayed' 19 | OPT_DEFAULT: 'Flag + Language name' 20 | OPT_FLAG: 'Only the flag' 21 | OPT_NAME: 'Only the language name' 22 | 23 | # French 24 | fr: 25 | PLUGINS: 26 | LANGUAGE_SELECTOR: 27 | PLUGIN_STATUS: 'Statut du plugin' 28 | BUILT_IN_CSS: 'Utiliser CSS du plugin' 29 | UNTRANSLATED_PAGES: 30 | LABEL: 'Comportement des pages non-traduites' 31 | HELP: 'Définit le comportement des liens lorsque la page n''existe pas dans la langue courante, ou bien existe mais non publié' 32 | OPT_NONE: 'Affiche le langage (par défaut)' 33 | OPT_REDIR: 'Affiche le langage, lié à l''URL de base' 34 | OPT_HIDE: 'Cache le langage' 35 | BUTTON_DISPLAY: 36 | LABEL: 'Affichage du boutton' 37 | HELP: 'Définit l''affichage du bouton de language sélectioné' 38 | SELECT_DISPLAY: 39 | LABEL: 'Affichage du sélecteur' 40 | HELP: 'Définit l''affichage du sélecteur de language' 41 | OPT_DEFAULT: 'Drapeau + Nom de la langue' 42 | OPT_FLAG: 'Seulement le drapeau' 43 | OPT_NAME: 'Seulement le nom de la langue' 44 | 45 | # Italian 46 | it: 47 | PLUGINS: 48 | LANGUAGE_SELECTOR: 49 | PLUGIN_STATUS: 'Status del plugin' 50 | BUILT_IN_CSS: 'Utilizzare CSS del plugin' 51 | UNTRANSLATED_PAGES: 52 | LABEL: 'Comportamento delle pagine non-tradotte' 53 | HELP: 'Determina il comportamento del link quando la pagina attuale non esiste in quella lingua, oppure esiste ma non è stata pubblicata.' 54 | OPT_NONE: 'Esibire lingua (default)' 55 | OPT_REDIR: 'Esibire lingua, linkare all''URL di base' 56 | OPT_HIDE: 'Nascondere lingua' 57 | BUTTON_DISPLAY: 58 | LABEL: 'Presentazione del tasto' 59 | HELP: 'Definisce la presentazione del tasto della lingua selezionata' 60 | SELECT_DISPLAY: 61 | LABEL: 'Presentazione del selettore' 62 | HELP: 'Definisce la presentazione del selettore di lingua' 63 | OPT_DEFAULT: 'Bandiera + Nome della lingua' 64 | OPT_FLAG: 'Soltanto la bandiera' 65 | OPT_NAME: 'Soltanto il nome della lingua' 66 | 67 | # Portuguese (Brazil) 68 | pt-br: 69 | PLUGINS: 70 | LANGUAGE_SELECTOR: 71 | PLUGIN_STATUS: 'Status do plugin' 72 | BUILT_IN_CSS: 'Utilizar CSS do plugin' 73 | UNTRANSLATED_PAGES: 74 | LABEL: 'Comportamento das páginas não-traduzidas' 75 | HELP: 'Determina o comportamento do link quando a página atual não existe naquela língua, ou existe mas não está publicada.' 76 | OPT_NONE: 'Mostrar língua (default)' 77 | OPT_REDIR: 'Mostrar língua, linkar para o URL de base' 78 | OPT_HIDE: 'Esconder língua' 79 | BUTTON_DISPLAY: 80 | LABEL: 'Apresentação do botão' 81 | HELP: 'Define a apresentação do botão da língua selecionada' 82 | SELECT_DISPLAY: 83 | LABEL: 'Apresentação do seletor' 84 | HELP: 'Define a apresentação do seletor de língua' 85 | OPT_DEFAULT: 'Bandeira + Nome da língua' 86 | OPT_FLAG: 'Apenas a bandeira' 87 | OPT_NAME: 'Apenas o nome da língua' -------------------------------------------------------------------------------- /templates/partials/language-selector.hreflang.html.twig: -------------------------------------------------------------------------------- 1 | {% set langobj = grav['language'] %} 2 | {% for key in language_selector.languages %} 3 | {% if key == language_selector.current %} 4 | {% set lang_url = page.url %} 5 | {% else %} 6 | {% set lang_url = base_url_simple ~ langobj.getLanguageURLPrefix(key) ~ language_selector.page_route ~ page.urlExtension ?: '/' %} 7 | {% endif %} 8 | 9 | {% endfor %} -------------------------------------------------------------------------------- /templates/partials/language-selector.html.twig: -------------------------------------------------------------------------------- 1 |
2 | 11 | 12 | 49 |
50 | --------------------------------------------------------------------------------