{"id":21954178,"url":"https://github.com/cssobj/cssobj-plugin-localize","last_synced_at":"2026-05-02T01:33:36.003Z","repository":{"id":72105919,"uuid":"64310468","full_name":"cssobj/cssobj-plugin-localize","owner":"cssobj","description":"Localize class names for cssobj.","archived":false,"fork":false,"pushed_at":"2018-03-22T01:41:03.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T09:09:07.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/cssobj.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}},"created_at":"2016-07-27T13:24:55.000Z","updated_at":"2018-03-22T01:41:04.000Z","dependencies_parsed_at":"2023-02-24T05:15:25.736Z","dependency_job_id":null,"html_url":"https://github.com/cssobj/cssobj-plugin-localize","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/cssobj%2Fcssobj-plugin-localize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssobj%2Fcssobj-plugin-localize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssobj%2Fcssobj-plugin-localize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cssobj%2Fcssobj-plugin-localize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cssobj","download_url":"https://codeload.github.com/cssobj/cssobj-plugin-localize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245001901,"owners_count":20545330,"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-11-29T07:16:55.290Z","updated_at":"2026-05-02T01:33:35.920Z","avatar_url":"https://github.com/cssobj.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cssobj-plugin-localize\n\n[![Join the chat at https://gitter.im/css-in-js/cssobj](https://badges.gitter.im/css-in-js/cssobj.svg)](https://gitter.im/css-in-js/cssobj) [![Build Status](https://travis-ci.org/cssobj/cssobj-plugin-localize.svg?branch=master)](https://travis-ci.org/cssobj/cssobj-plugin-localize)\n\nLocalize class names for cssobj. Put CSS Class names into different name **space**.\n\n## Install\n\ninstall from github directly:\n\n``` javascript\nnpm install cssobj/cssobj-plugin-localize\n```\n\n## API\n\n### localize(space: boolean|string, localNames: object) -\u003e {selector: function}\n\n#### space\n\n- Type: `String` | `Boolean`\n\n- Default: Random String\n\nIf pass empty string `''`, will use `''` (empty space)\n\nIf pass other falsy value, will use default.\n\n#### localNames\n\n- Type: `Object`\n\n- Default: `{}`\n\n**key/val** pair to define how class name map into local name.\n\nKey is original class name.\n\nVal is localized name.\n\n#### *RETURN*\n\n#### Add method to `result`\n\nThe cssobj `result` object will be added 2 method by this plugin:\n\n##### - `result.mapSel({string} selector){ return {string} mappedSelector }`\n\nReplace class names in `selector` string, with all class names replace by localized version. (**keep dot** \u003ckbd\u003e.\u003c/kbd\u003e)\n\n##### - `result.mapClass({string} classList){ return {string} mappedClassList }`\n\nTreat `classList` string as space seperated class list(e.g. in `\u003cdiv class=\"abc efg\"\u003e`),\n\nReplace all seperated word by localized version. (**without dot**)\n\nThe classList can be `'nav item'`, or `'.nav .item'` form, all \u003ckbd\u003e.\u003c/kbd\u003e will be replaced by space.\n\nThe returned class string is `.trim()`ed, you need polyfill this method if you want support IE \u003c 9.\n\n##### Above 2 method both can accept `.!class1 .!class2` escaped for global space.\n\n## Usage\n\n#### - Localize\n\n``` javascript\nvar localize = require('cssobj-plugin-localize')\nvar ret = cssobj({'.item': {color: 'red'}}, {\n  plugins:[  localize() ]\n})\n// css is =\u003e ._1hisnf23_item {color: red;}\n\n// you can get the mapped selector using:\nret.mapSel('.nav .item')  // === ._1hisnf23_nav ._1hisnf23_item\n\n// you can get the mapped class list using:\n// (used in className attributes for HTML tag)\nret.mapClass('.nav .item')  // === _1hisnf23_nav _1hisnf23_item\nret.mapClass('nav item')  // === _1hisnf23_nav _1hisnf23_item\n\n```\n\n#### - Global\n\nThere's a way to make class **Global**\n\n##### - .!className\n\nJust add **!** in front of class name, if you want it global.\n\n``` javascript\nvar ret = cssobj({'body .!nav .!item .login': {color: 'red'}}, {\n  plugins:[  localize() ]\n})\n// css is =\u003e body .nav .item ._1hisnf23_login {color: red;}\n```\n\n#### - Custom Prefix\n\nYou can control the space:\n\n``` javascript\nvar ret = cssobj({'body .nav .item .login': {color: 'red'}}, {\n  plugins:[  localize('_your_space_') ]\n})\n// css is =\u003e body ._your_space_nav ._your_space_item ._your_space_login {color: red;}\n```\n\n\n#### - Custom Local Names\n\nYou can control the map for each class name:\n\n``` javascript\nvar ret = cssobj({'body .nav .!item .login': {color: 'red'}}, {\n  plugins:[  localize(null, {nav: '_abc_'}) ]\n})\n// css is =\u003e body ._abc_ .!item ._1hisnf23_login {color: red;}\n```\n\n#### - Get the class map\n\n``` javascript\nvar ret = cssobj({'body .nav .item .login': {color: 'red'}}, {\n  plugins:[  localize('_space_', {nav: '_abc_'}) ]\n})\n\nret.mapSel('.nav .item .!pushRight')  // === ._abc_ ._space_item .pushRight\nret.mapSel('.!nav .!item .pushRight')  // === .nav .item ._space_pushRight\nret.mapClass('item nav !pushRight')  // ===  _space_item _abc_ pushRight\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssobj%2Fcssobj-plugin-localize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcssobj%2Fcssobj-plugin-localize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcssobj%2Fcssobj-plugin-localize/lists"}