{"id":28002218,"url":"https://github.com/jools-r/jcr_langprefix","last_synced_at":"2025-06-27T23:05:21.541Z","repository":{"id":291178238,"uuid":"976847902","full_name":"jools-r/jcr_langprefix","owner":"jools-r","description":"Custom language prefix url scheme and permlink handler","archived":false,"fork":false,"pushed_at":"2025-05-09T09:07:47.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T03:41:20.637Z","etag":null,"topics":["textpattern","textpattern-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jools-r.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-05-02T21:34:10.000Z","updated_at":"2025-05-09T09:07:51.000Z","dependencies_parsed_at":"2025-05-02T22:30:48.897Z","dependency_job_id":"791ede0e-1b63-4ad6-bcc2-0ad9f5910608","html_url":"https://github.com/jools-r/jcr_langprefix","commit_stats":null,"previous_names":["jools-r/jcr_langprefix"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jools-r/jcr_langprefix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jools-r%2Fjcr_langprefix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jools-r%2Fjcr_langprefix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jools-r%2Fjcr_langprefix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jools-r%2Fjcr_langprefix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jools-r","download_url":"https://codeload.github.com/jools-r/jcr_langprefix/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jools-r%2Fjcr_langprefix/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262347474,"owners_count":23296894,"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":["textpattern","textpattern-plugin"],"created_at":"2025-05-09T00:16:33.324Z","updated_at":"2025-06-27T23:05:21.519Z","avatar_url":"https://github.com/jools-r.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jcr_langprefix\n\n## Custom language URL scheme handler\n\nThis plugin detects and inserts a language prefix to Textpattern URLs\nfor use in multilingual sites, for example:\n\n    /fr/section-name\n    /de/section-name/article-url-title\n    /en/category/category-name\n\nwill be treated by Textpattern as follows:\n\n    /section-name                     -\u003e lang:fr\n    /section-name/article-url-title   -\u003e lang:de\n    /category/category-name           -\u003e lang:en\n\nYou do not need to create sections for each language. The plugin\nincludes public tags to output and detect the currently set language\nprefix, to create language switchers and to output matching text\nstrings.\n\n#### Incoming URLs\n\njcr_langprefix works invisibly in the background, storing the language\nprefix for later use in your page code while passing the remainder of\nthe URL to textpattern for handling as normal.\n\n\u003cins\u003eIf no language prefix is provided\u003c/ins\u003e, the default language\n(see settings) is set in the background (but *not* added to the url) and\nthe url works as normal.\n\n\u003cins\u003eIf an unknown language prefix is provided\u003c/ins\u003e, i.e. one not in\nthe list of permitted languages (see settings), Textpattern will treat\nit as a regular section name and return a \"404 Not Found\" if it does not\nexist.\n\n#### Outgoing links\n\nThe plugin can automatically prepend a language prefix to txp:tags with\na `link=\"1\"` attribute and to `txp:permlink`. You can optionally disable\nthis in the plugin settings. You must then construct your own\nlanguage-specific links.\n\n### Please note\n\n\u003cins\u003eThe plugin only handles the language prefix in the url. It has no\nconcept of whether the actual page is in a particular\nlanguage.\u003c/ins\u003e That means `/en/vegetables/` and `/de/vegetables`\nand `/vegetables/` are all identical, i.e. the \"vegetables\" section in\nTextpattern. It is up to you to define what information should be shown\nfor a page's current language prefix.\n\nFor example, define article custom_fields to denote different language\nfields, or denote an article's language. Similarly, use\n[jcr_section_custom](https://github.com/jools-r/jcr_section_custom) or\n[jcr_category_custom](https://github.com/jools-r/jcr_category_custom) to\ndefine language specific fields for sections and categories. You can\nthen use this plugin's public tags to output specific fields.\n\nAlso, make sure to provide correct canonical urls to avoid url\nduplication in search machine results.\n\n## Installation \u0026 settings\n\nPaste the code into the Admin › Plugins tab, install and enable the\nplugin.\n\nTo configure the plugin, visit the plugin options on the *Admin ›\nPreferences › Language URL prefixes* panel. You have options to set:\n\n- the permitted language prefixes. Specify these as a comma-separated\n  list of prefixes, e.g `de, it, fr`.\n- the default language prefix.\n- whether the plugin should automatically add language-prefixes to\n  permlinks.\n\n### Language strings\n\nTo use the language-aware `jcr_text` tag to output language strings\nstored in Textpattern, make sure the relevant languages have been\ninstalled on the *Admin › Languages* panel. The language code must match\nthe language prefix, e.g. to use US English (TXP language code: en-us),\nyour language prefix will need to be `en-us`.\n\n## Tag: jcr_lang\n\nOutputs the language prefix from the current page url.\n\n    \u003chtml lang=\"\u003ctxp:jcr_lang /\u003e\"\u003e\n\n## Tag: jcr_if_lang\n\nConditionally show output when it matches the current language prefix.\n\n    \u003ctxp:jcr_if_lang lang=\"en\"\u003eYour English-language text\u003c/txp:jcr_if_lang\u003e\n\nYou can additionally check if the language matches the preset default\nlanguage:\n\n    \u003ctxp:jcr_if_lang lang=\"default\"\u003e\n        \u003ctxp:body /\u003e\n    \u003ctxp:else /\u003e\n        \u003ctxp:custom_field name='body_\u003ctxp:jcr_lang /\u003e' escape=\"textile\" /\u003e\n    \u003c/txp:jcr_if_lang\u003e\n\n## Tag: jcr_langswitch\n\nOutput a link to the current page -- or the site root -- with a\ndifferent language prefix.\n\n#### Attributes\n\n**lang**\\\nThe target language\\\nExample: `\u003ctxp:jcr_langswitch lang=\"de\" /\u003e` will return\n`domain.com/de/section-name/my-current-page`.\n\n**root**\\\nThe site root with the specified language\\\nExample: `\u003ctxp:jcr_langswitch lang=\"de\" root /\u003e` will return\n`domain.com/de/`.\n\n## Tag: jcr_text\n\nA drop-in language-aware replacement for\n[txp:text](https://docs.textpattern.com/tags/text) that shows a\npre-translated language string stored in Textpattern in the current\npage's language -- or in a specified language.\n\n    \u003ctxp:jcr_text item=\"categories\" /\u003e\n\nwill show:\n\n- \"Categories\" on an `/en/` page,\n- \"Kategorien\" on a `/de/` page, and\n- \"Catégories\" on a `/fr/` page.\n\n**lang**\\\nSpecify a specific language\\\nExample: `\u003ctxp:jcr_text item=\"categories\" lang=\"fr\" /\u003e` will return\n\"Catégories\" regardless of the current page's language prefix\n\n### Tip\n\nTo add language strings of your own in multiple languages, use\n[smd_babel](https://github.com/bloke/smd_babel).\n\n## Usage examples\n\nUse the public tag directly with txp:evaluate or store it in a variable\nfor use in your template.\n\n### A very simple example\n\n    \u003ctxp:jcr_if_lang lang=\"de\"\u003e\n        \u003ch1\u003eWillkommen!\u003c/h1\u003e\n    \u003ctxp:else /\u003e\n        \u003ch1\u003eWelcome!\u003c/h1\u003e\n    \u003c/txp:jcr_if_lang\u003e\n\n### Per-language text snippets\n\n    \u003c!-- predefined variables holding a text snippet in each language --\u003e\n    \u003ctxp:variable name=\"rewelcome_en\"\u003eWelcome back!\u003c/txp:variable\u003e\n    \u003ctxp:variable name=\"rewelcome_de\"\u003eWillkommen zurück!\u003c/txp:variable\u003e\n    \u003ctxp:variable name=\"rewelcome_fr\"\u003eBon retour!\u003c/txp:variable\u003e\n    \u003c!-- use language variable as tag-in-tag (with single quotes) --\u003e\n    \u003ch1\u003e\u003ctxp:variable name='rewelcome_\u003ctxp:jcr_lang /\u003e' /\u003e\u003c/h1\u003e\n\n### Per-language article fields\n\nYou can expand on this to show an article's body text in different\nlanguages. First install\n[glz_custom_fields](https://github.com/jools-r/glz_custom_fields).\nCreate new custom fields and define then as textareas. Suffix their name\nwith the language code, e.g. `body_de`, `body_fr` etc. In your article\nwrite tab, enter your translations in the respective body fields.\n\nTo show the language you want in your page template, combine the\nprinciples of the above two examples:\n\n    \u003ctxp:jcr_if_lang lang=\"en\"\u003e\n        \u003ctxp:body /\u003e\n    \u003ctxp:else /\u003e\n        \u003ctxp:custom_field name='body_\u003ctxp:jcr_lang /\u003e' escape=\"textile\" /\u003e\n    \u003c/txp:jcr_if_lang\u003e\n\n### Per-language article fields with warning for missing content\n\nYou'll probably want to add some safeguards to show something else if a\ntranslation is missing or to only allow defined languages. For example:\n\n    \u003ctxp:jcr_if_lang lang=\"default\"\u003e\n        \u003ctxp:body /\u003e\n    \u003ctxp:else /\u003e\n        \u003ctxp:evaluate test=\"custom_field\"\u003e\n            \u003ctxp:custom_field name='body_\u003ctxp:jcr_lang /\u003e' escape=\"textile\" /\u003e\n        \u003ctxp:else /\u003e\n            \u003cp class=\"alert warning\"\u003eThis article is not yet available in your language.\u003c/p\u003e\n            \u003ctxp:body /\u003e\n        \u003c/txp:evaluate\u003e\n    \u003c/txp:jcr_if_lang\u003e\n\n### Language switcher principle\n\nAn example of a simple language switcher that switches between different\nlanguage versions of the current page:\n\n    \u003cnav\u003e\n        \u003cul\u003e\n            \u003cli\u003ctxp:jcr_if_lang lang=\"en\"\u003e class=\"active\"\u003c/txp:jcr_if_lang\u003e\u003e\n                \u003ca href=\"\u003ctxp:jcr_langswitch lang=\"en\" /\u003e\"\u003eEN\u003c/a\u003e\n            \u003c/li\u003e\n            \u003cli\u003ctxp:jcr_if_lang lang=\"de\"\u003e class=\"active\"\u003c/txp:jcr_if_lang\u003e\u003e\n                \u003ca href=\"\u003ctxp:jcr_langswitch lang=\"de\" /\u003e\"\u003eDE\u003c/a\u003e\n            \u003c/li\u003e\n            \u003cli\u003ctxp:jcr_if_lang lang=\"fr\"\u003e class=\"active\"\u003c/txp:jcr_if_lang\u003e\u003e\n                \u003ca href=\"\u003ctxp:jcr_langswitch lang=\"fr\" /\u003e\"\u003eFR\u003c/a\u003e\n            \u003c/li\u003e\n        \u003c/ul\u003e\n    \u003c/nav\u003e\n\n## Changelog\n\n### v 0.2 (jcr)\n\n- Renamed plugin and main tag:\n  - jcr_langprefix_url -\\\u003e jcr_lang\n- New tags:\n  - jcr_if_lang\n  - jcr_langswitch\n  - jcr_text\n- Added plugin prefs (no longer necessary to edit plugin code)\n- Updated help accordingly\n\n### v 0.1.1 (jcr)\n\n- Support installations in subdirectories (e.g. when using localhost)\n- Silence error on base page with no subsequent path (thanks gil)\n\n### v 0.1 (jcr)\n\n- Custom URL handling via callback\n- Custom permlink function\n- Custom pagelink function\n- Public-side language prefix tag\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjools-r%2Fjcr_langprefix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjools-r%2Fjcr_langprefix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjools-r%2Fjcr_langprefix/lists"}