{"id":16894276,"url":"https://github.com/jsor/string-formatter","last_synced_at":"2025-04-11T13:33:54.217Z","repository":{"id":57002413,"uuid":"42186500","full_name":"jsor/string-formatter","owner":"jsor","description":"Localized formatting of personal names, addresses and telephone numbers.","archived":false,"fork":false,"pushed_at":"2022-10-17T06:34:48.000Z","size":54,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-03T22:30:09.785Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/jsor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-09T15:15:04.000Z","updated_at":"2022-10-17T06:27:28.000Z","dependencies_parsed_at":"2022-08-21T12:10:41.534Z","dependency_job_id":null,"html_url":"https://github.com/jsor/string-formatter","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fstring-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fstring-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fstring-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fstring-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsor","download_url":"https://codeload.github.com/jsor/string-formatter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239648548,"owners_count":19674392,"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-13T17:18:11.489Z","updated_at":"2025-02-19T11:30:43.019Z","avatar_url":"https://github.com/jsor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"StringFormatter\n===============\n\nLocalized formatting of personal names, addresses and telephone numbers.\n\n[![Build Status](https://github.com/jsor/string-formatter/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jsor/string-formatter/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/jsor/string-formatter/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/jsor/string-formatter?branch=main)\n\n**Note**: At the moment, only a NameFormatter is available. Address and\ntelephone formatters will follow.\n\nInstallation\n------------\n\nInstall the latest version with [Composer](https://getcomposer.org).\n\n```bash\ncomposer require jsor/string-formatter\n```\n\nCheck the [Packagist page](https://packagist.org/packages/jsor/string-formatter)\nfor all available versions.\n\nNameFormatter\n-------------\n\nThe NameFormatter formats the appropriate representation of a person’s name for\na locale by the given name parts.\n\n```php\nuse Jsor\\NameFormatter;\n\n$nameParts = [\n    'given_name' =\u003e 'John',\n    'family_name' =\u003e 'Doe',\n    'salutation' =\u003e 2 // name_mr\n];\n\n$enUsFormatter = new NameFormatter('en_US');\necho $enUsFormatter-\u003eformat($nameParts).\"\\n\";\n\n$deDeFormatter = new NameFormatter('de_DE');\necho $deDeFormatter-\u003eformat($nameParts).\"\\n\";\n\n$zhCnFormatter = new NameFormatter('zh_CN');\necho $zhCnFormatter-\u003eformat($nameParts).\"\\n\";\n```\n\nThe above example will output:\n\n```\nMr. John Doe\nHerr John Doe\nDoe John 先生\n```\n\nA custom pattern can be passed as the second argument to the constructor.\n\n```php\nuse Jsor\\NameFormatter;\n\n$formatter = new NameFormatter('en_US', '%d%t%g%t%m%t%f');\necho $formatter-\u003eformat([\n    'given_name' =\u003e 'John',\n    'family_name' =\u003e 'Doe',\n    'salutation' =\u003e 'Mr.',\n]);\n```\n\nThe above example will output:\n\n```\nMr. John Doe\n```\n\n### Pattern\n \nThe pattern argument can contain any combination of characters and field\ndescriptors.\n\nThe following field descriptor are supported.\n\n* `%f`\n    Family names.\n* `%F`\n    Family names in uppercase.\n* `%g`\n    First given name.\n* `%G`\n    First given initial.\n* `%l`\n    First given name with latin letters. In some cultures, eg on Taiwan it is\n    customary to also have a first name written with Latin letters, although the\n    rest of the name is written in another script.\n* `%o`\n    Other shorter name, eg. \"Bill\".\n* `%m`\n    Additional given names.\n* `%M`\n    Initials for additional given names.\n* `%p`\n    Profession.\n* `%d`\n    Salutation, supporting the FDCC-sets conventions, with `1` for `name_gen`,\n    `2` for `name_mr`, `3` for `name_mrs`, `4` for `name_miss`,\n    `5` for `name_ms`.\n* `%s`\n    Full Salutation, such as \"Doctor\".\n* `%S`\n    Abbreviated salutation, such as \"Mr.\" or \"Dr.\"\n* `%t`\n    If the preceding field descriptor resulted in an empty string, then the\n    empty string, else a space.\n\n### Values\n\nThe array argument passed to `format()` can define a value for each field\ndescriptor. The keys can be either the descriptor character or a named key.\n\nThe following keys are supported.\n\n* `family_name`, `family_names` or `f` (for `%f`)\n* `family_name_in_uppercase`, `family_names_in_uppercase` or `F` (for `%F`)\n* `given_name`, `given_names` or `g` (for `%g`)\n* `given_initial`, `given_initials` or `G` (for `%G`)\n* `given_name_with_latin_letters`, `given_names_with_latin_letters` or `l` (for `%l`)\n* `other_shorter_name`, `other_shorter_names` or `o` (for `%o`)\n* `additional_given_name`, `additional_given_names` or `m` (for `%m`)\n* `initials_for_additional_given_name`, `initials_for_additional_given_names` or `M` (for `%M`)\n* `profession`, `professions` or `p` (for `%p`)\n* `salutation`, `salutations` or `d` (for `%d`)\n* `full_salutation`, `full_salutations` or `s` (for `%s`)\n* `abbreviated_salutation`, `abbreviated_salutations` or `S` (for `%S`)\n\nLicense\n-------\n\nCopyright (c) 2015-2022 Jan Sorgalla.\nReleased under the [MIT](LICENSE) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsor%2Fstring-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsor%2Fstring-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsor%2Fstring-formatter/lists"}