{"id":18273452,"url":"https://github.com/arraypress/localization-manager","last_synced_at":"2025-04-09T03:40:39.443Z","repository":{"id":257811762,"uuid":"868177733","full_name":"arraypress/localization-manager","owner":"arraypress","description":"A robust utility for managing localized text and content across different WordPress plugins, offering centralized registration, storage, and retrieval of translations.","archived":false,"fork":false,"pushed_at":"2024-12-07T21:23:25.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T22:14:00.154Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arraypress.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":"2024-10-05T17:14:50.000Z","updated_at":"2024-10-05T17:17:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"c3b367f0-4c2c-40d3-8b97-7123d5f09050","html_url":"https://github.com/arraypress/localization-manager","commit_stats":null,"previous_names":["arraypress/localization-manager"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Flocalization-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Flocalization-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Flocalization-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Flocalization-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/localization-manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974584,"owners_count":21026742,"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-05T12:06:30.728Z","updated_at":"2025-04-09T03:40:39.438Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","readme":"# WordPress Localization Manager Library\n\nThe WordPress Localization Manager Library simplifies the process of managing localizations within a WordPress\nenvironment. It provides utility functions that leverage the LocalizationManager class to handle the registration and\nretrieval of localized text for various WordPress plugins.\n\n## Features\n\n- Easy registration of localizations for plugins\n- Integration with WordPress translation functions\n- Retrieval of localized text with support for plural forms and lowercase options\n- Addition of new localized text to existing plugins\n- Checking for the existence of localized text\n- Error handling with optional callback function\n- Escaping functions for secure output\n\n## Requirements\n\n- PHP 7.4 or higher\n- WordPress 6.6.2 or higher\n\n## Installation\n\nInstall the library using Composer:\n\n```bash\ncomposer require arraypress/localization-manager\n```\n\n## Usage\n\n### Registering Plugin Localizations\n\nWhen registering localizations, use WordPress translation functions to ensure the text is translatable:\n\n```php\n// Register localizations for this plugin\nregister_localized_text( __FILE__, [\n    'hello_world' =\u003e [\n        'singular' =\u003e __( 'Hello, World!', 'localization-demo' ),\n        'plural'   =\u003e __( 'Hello, Worlds!', 'localization-demo' )\n    ],\n    'goodbye'     =\u003e __( 'Goodbye!', 'localization-demo' )\n] );\n```\n\n### Getting Localized Text\n\n```php\n$plugin_file = __FILE__; // Your plugin's main file\n$text = get_localized_text( 'hello_world', $plugin_file );\n$plural_text = get_localized_text( 'hello_world', $plugin_file, true );\n$lowercase_text = get_localized_text( 'hello_world', $plugin_file, false, true );\n```\n\n### Adding New Localized Text\n\nWhen adding new text, also use WordPress translation functions:\n\n```php\n$plugin_file = __FILE__; // Your plugin's main file\nadd_localized_text( 'welcome', __( 'Welcome to our plugin!', 'textdomain' ), $plugin_file );\n```\n\n### Checking if Localized Text Exists\n\n```php\nif ( localized_text_exists( 'welcome', __FILE__ ) ) {\n    // Text exists, do something\n}\n```\n\n### Echoing Localized Text\n\n```php\necho_localized_text( 'hello_world', $plugin_file );\n```\n\n### Escaping Localized Text\n\n```php\n$escaped_text = esc_localized_text( 'hello_world', $plugin_file );\necho_esc_localized_text( 'hello_world', $plugin_file );\n```\n\n## Error Handling\n\nAll functions accept an optional error callback function. If provided, this function will be called with any exceptions\nthat occur during execution.\n\n```php\n$error_callback = function( $exception ) {\n    // Handle or log the exception\n};\n\nregister_localized_text( $plugin_file, $localizations, $error_callback );\n```\n\n## Full Example\n\nHere's a complete example demonstrating the usage of the Localization Manager within a WordPress plugin:\n\n```php\n\u003c?php\n/**\n * Plugin Name: Localization Demo Plugin\n * Plugin URI: https://example.com/localization-demo-plugin\n * Description: Demonstrates the functionality of the LocalizationManager\n * Version: 1.0.0\n * Author: Your Name\n * Author URI: https://example.com\n * License: GPL2+\n * License URI: https://www.gnu.org/licenses/gpl-2.0.html\n * Text Domain: localization-demo\n * Domain Path: /languages\n */\n\n// Initialize the plugin\nfunction localization_demo_init() {\n\n\t// Register localizations for this plugin\n\tregister_localized_text( __FILE__, [\n\t\t'hello_world' =\u003e [\n\t\t\t'singular' =\u003e __( 'Hello, World!', 'localization-demo' ),\n\t\t\t'plural'   =\u003e __( 'Hello, Worlds!', 'localization-demo' )\n\t\t],\n\t\t'goodbye'     =\u003e __( 'Goodbye!', 'localization-demo' )\n\t] );\n\n\t// Add additional text\n\tadd_localized_text( 'welcome', __( 'Welcome to our plugin!', 'localization-demo' ), __FILE__ );\n\n\t// Demonstrate usage of the localization functions\n\tadd_action( 'admin_notices', 'localization_demo_admin_notices' );\n}\n\nadd_action( 'plugins_loaded', 'localization_demo_init' );\n\n// Display admin notices to showcase the localization functionality\nfunction localization_demo_admin_notices() {\n\t?\u003e\n    \u003cdiv class=\"notice notice-info\"\u003e\n        \u003cp\u003e\u003c?php echo_esc_localized_text( 'hello_world', __FILE__ ); ?\u003e\u003c/p\u003e\n        \u003cp\u003e\u003c?php echo_esc_localized_text( 'hello_world', __FILE__, true ); ?\u003e\u003c/p\u003e\n        \u003cp\u003e\u003c?php echo_esc_localized_text( 'goodbye', __FILE__ ); ?\u003e\u003c/p\u003e\n        \u003cp\u003e\u003c?php echo_esc_localized_text( 'welcome', __FILE__ ); ?\u003e\u003c/p\u003e\n        \u003cp\u003e\n\t\t\t\u003c?php\n\t\t\tif ( localized_text_exists( 'nonexistent', __FILE__ ) ) {\n\t\t\t\techo 'This should not appear.';\n\t\t\t} else {\n\t\t\t\techo 'The \"nonexistent\" key does not exist.';\n\t\t\t}\n\t\t\t?\u003e\n        \u003c/p\u003e\n    \u003c/div\u003e\n\t\u003c?php\n}\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the GPL2+ License.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Flocalization-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Flocalization-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Flocalization-manager/lists"}