{"id":16854502,"url":"https://github.com/davispuh/fuelphp-lang","last_synced_at":"2025-03-18T10:44:23.886Z","repository":{"id":6563487,"uuid":"7805353","full_name":"davispuh/FuelPHP-Lang","owner":"davispuh","description":"Extended Lang class for FuelPHP","archived":false,"fork":false,"pushed_at":"2013-01-26T00:38:48.000Z","size":113,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T11:09:42.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davispuh.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}},"created_at":"2013-01-24T19:32:37.000Z","updated_at":"2018-05-09T01:54:38.000Z","dependencies_parsed_at":"2022-09-14T04:31:09.468Z","dependency_job_id":null,"html_url":"https://github.com/davispuh/FuelPHP-Lang","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davispuh%2FFuelPHP-Lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davispuh%2FFuelPHP-Lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davispuh%2FFuelPHP-Lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davispuh%2FFuelPHP-Lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davispuh","download_url":"https://codeload.github.com/davispuh/FuelPHP-Lang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244207668,"owners_count":20416100,"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":[],"created_at":"2024-10-13T13:55:39.175Z","updated_at":"2025-03-18T10:44:23.869Z","avatar_url":"https://github.com/davispuh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Extended Lang class for FuelPHP\n\nThis extended Lang class supports localized language URLs\n```\nhttp://domain/lang1/controller/method\nhttp://domain/lang2/controller/method\n```\n\nOnly Lang class is changed and without introducing any side-effects thus making it fully backward compatible and keeping FuelPHP API same, but adding additional functionality.\n\n### Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Authors](#authors)\n- [Unlicense](#unlicense)\n- [Contribute](#contribute)\n\n## Installation\n\nYou can install it with composer or just copy `lang.php` to your `app/classes/`\n\nthen in your `app/bootstrap.php` add\n```php\nAutoloader::add_class('Lang', VENDORPATH . 'davispuh/fuelphp-lang/classes/lang.php');\n```\n\nor if you copied it then\n\n```php\nAutoloader::add_class('Lang', APPPATH . 'classes/lang.php');\n```\n\n## Usage\n\nTo use this extended Lang class there are required few code changes, but nothing much.\n\n1. all links which are supposed to be for same language must be replaced with\n`Lang::localized($uri)`, eg. `\u003ca href=\"\u003c?php echo Lang::localized('/blog/article/')?\u003e\"/\u003eArticle\u003c/a\u003e`\n(Note: currently `localized` doesn't support schema or relative urls, and it expects that uri starts with `/` but it can be implemented if needed, now can do just `'https://domain'.Lang::localized('/blog/article/')`)\n2. make links which change language. either use `Lang::localized('/blog/article/','ru')` or directly write `\u003ca href=\"/ru\"\u003eRU\u003c/a\u003e`\n3. in app `config.php` add available languages `'languages' =\u003e Array('en', 'ru')`\n4. change `routes.php` config to also include localized routing.\n\n#### `routes.php` config changes explained\n\nWill need routes for both cases when language is included in URI and when isn't.\nSo will need to add another `_root_` ie. `$routes[$langs]` and all other routes prefixed with `$routes[(({$langs})/)?route]`\n\nThere's 4 possible configurations.\n\n##### 1.\nSEO friendly. Default language without any prefix. ie. `http://domain/controller` and all other languages `http://domain/lang/controller`. BUT `http://domain/default_lang/controller` returns 404\n\n`config.php`: `'language' =\u003e 'en'` // specify which language will be served as default. without included in URL\n\n`routes.php`\n```php\n\u003c?php\n\n$languages = Config::get('languages');\nunset($languages[0]);\n$langs = implode('|', $languages);\n\nreturn array(\n'_root_' =\u003e 'welcome/index', // The default route\n\"({$langs})\" =\u003e 'welcome/index', // The default route in other language\n\"(({$langs})/)?hello(/:name)?\" =\u003e array('welcome/hello', 'name' =\u003e 'hello'),\n);\n```\n\n\n##### 2.\nDefault language without any prefix. ie. `http://domain/controller`, BUT `http://domain/default_lang/controller` will still work.\n\neverything same as previous, just without `unset($languages[0]);`\n\n##### 3.\nAll languages `http://domain/lang/controller`. BUT `http://domain/controller` will return 404. There's exception to `_root_`, it will give default language (language_fallback).\n\n`config.php`: `'language' =\u003e ''` // no default language, MUST be in URL\n`'language_fallback' =\u003e 'en'` // Fallback language if language isn't in URL\n\n`routes.php`\n```\n\u003c?php\n\n$langs = implode('|', Config::get('languages'));\n\nreturn array(\n'_root_' =\u003e 'welcome/index', // The default route\n\"({$langs})\" =\u003e 'welcome/index', // The default route in other language\n\"(({$langs})/)?hello(/:name)?\" =\u003e array('welcome/hello', 'name' =\u003e 'hello'),\n);\n```\n\n##### 4.\nMake your own routes, unlimited possibilities. Maybe you don't have some article in that language? No problem, just give in default language or give page informing that it's not available.\n\n\n## Authors\n\nThis extended Lang class is implemented by me @davispuh\n\nOriginal FuelPHP Lang class is made by Fuel Development Team under MIT license\n\n## Unlicense\n\nAll text, documentation, code and files in this repository are in public domain (including this text, README).\nIt means you can copy, modify, distribute and include in your own work/code, even for commercial purposes, all without asking permission.\n\n## Contribute\n\nFeel free to improve anything what you see is improvable.\n\n\n**Warning**: By sending pull request to this repository you dedicate any and all copyright interest in pull request (code files and all other) to the public domain. (files will be in public domain even if pull request doesn't get merged)\n\nAlso before sending pull request you acknowledge that you own all copyrights or have authorization to dedicate them to public domain.\n\nIf you don't want to dedicate code to public domain or if you're not allowed to (eg. you don't own required copyrights) then DON'T send pull request.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavispuh%2Ffuelphp-lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavispuh%2Ffuelphp-lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavispuh%2Ffuelphp-lang/lists"}