Skip to content

Commit

Permalink
Merge pull request #6 from tomatophp/develop
Browse files Browse the repository at this point in the history
update translations
  • Loading branch information
3x1io authored Apr 18, 2024
2 parents 7dac48c + eef0afc commit 12dabc7
Show file tree
Hide file tree
Showing 25 changed files with 592 additions and 103 deletions.
81 changes: 81 additions & 0 deletions convert_translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

$directory = './'; // Change this to the path of your PHP files
$outputFile = 'lang/en/messages2.php'; // The file where the array will be saved

// This function scans directories recursively and processes each PHP file
function scanAndProcessDirectory($dir, &$messages)
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));

foreach ($iterator as $file) {
if ($file->isDir()) {
continue;
}

// Check if the file is a PHP or STUB file
$fileExtension = $file->getExtension();
if ($fileExtension === 'php' || $fileExtension === 'stub') {
processFile($file->getPathname(), $messages);
}
}
}

// This function processes each PHP file to find and convert __() strings
function processFile($filePath, &$messages)
{
$content = file_get_contents($filePath);
// Updated regex to exclude __() calls that contain 'Str::' after the opening __('
preg_match_all("/__\(\s*['\"](?!.*Str::)(.*?)['\"]\s*\)/", $content, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
$originalString = $match[1]; // The original string inside __()
// Check if the string contains '{{' and '}}', indicating a variable
if (strpos($originalString, '{{') !== false && strpos($originalString, '}}') !== false) {
continue; // Skip processing this match
}
$key = generateTransKey($originalString); // Generate a key for the trans() function
$messages['plugins'][$key] = $originalString;

// Prepare the replacement string
$replacement = "trans('filament-plugins::messages.plugins.$key')";
// Use preg_replace to replace only the first occurrence
$pattern = '/' . preg_quote($match[0], '/') . '/';
$content = preg_replace($pattern, $replacement, $content, 1);
}

// Write the modified content back to the file
file_put_contents($filePath, $content);
}

function generateTransKey($string)
{
// Handle the case where the string contains variable placeholders
if (strpos($string, '{{') !== false && strpos($string, '}}') !== false) {
return $string; // Return the string as is, assuming it's a variable
}

// Convert the string to a slug-like format
$key = strtolower(preg_replace('/[^a-zA-Z0-9]+/', '_', $string));

// Trim trailing underscores
$key = rtrim($key, '_');

return $key;
}

// This function saves the messages array to a PHP file
function saveMessagesToFile($messages, $filePath)
{
$export = var_export($messages, true);
$content = "<?php\n\nreturn $export;\n";
file_put_contents($filePath, $content);
}


// Main logic
$messages = [];
scanAndProcessDirectory($directory, $messages);
saveMessagesToFile($messages, $outputFile);

echo "Conversion completed. Check the $outputFile file.";
55 changes: 55 additions & 0 deletions lang/en/messages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

return [
'plugins' =>
[
'save' => 'Save',
'delete' => 'Delete',
'cancel' => 'Cancel',
'edit' => 'Edit',
'updated_successfully' => 'updated successfully',
'deleted_successfully' => 'deleted successfully',
'create' => 'Create',
'has_been_deleted' => 'Has Been Deleted',
'add_column' => 'Add Column',
'add_id' => 'Add Id',
'add_timestamps' => 'Add Timestamps',
'add_soft_deletes' => 'Add Soft Deletes',
'create_table' => 'Create Table',
'migrate' => 'Migrate',
'migrated' => 'Migrated',
'table_migrated_successfully' => 'Table migrated successfully.',
'generate' => 'Generate',
'error' => 'Error',
'docs' => 'Docs',
'table_does_not_exist_please_run_migrate' => 'Table does not exist please run migrate.',
'model_does_not_exist_please_generate_model_first' => 'Model does not exist please generate model first.',
'generated' => 'Generated',
'table_generated_successfully' => 'Table generated successfully.',
'plugins' => 'Plugins',
'settings' => 'Settings',
'disable' => 'Disable',
'plugin_disabled' => 'Plugin Disabled',
'the_plugin_has_been_disabled_successfully' => 'The plugin has been disabled successfully.',
'plugin_deleted' => 'Plugin Deleted',
'the_plugin_has_been_deleted_successfully' => 'The plugin has been deleted successfully.',
'active' => 'Active',
'you_need_to_run_autoload' => 'You need to run autoload',
'you_need_to_run_composer_dump_autoload_before_activating_the_plugin' => 'You need to run composer dump-autoload before activating the plugin.',
'plugin_enabled' => 'Plugin Enabled',
'the_plugin_has_been_enabled_successfully' => 'The plugin has been enabled successfully.',
'create_plugin' => 'Create Plugin',
'plugin_name' => 'Plugin Name',
'e_g_my_plugin' => 'e.g. My Plugin',
'description' => 'Description',
'e_g_a_simple_plugin_for_filament' => 'e.g. A simple plugin for Filament',
'import_plugin' => 'Import Plugin',
'plugin_file' => 'Plugin File',
'plugin_uploaded' => 'Plugin Uploaded',
'the_plugin_has_been_uploaded_successfully' => 'The plugin has been uploaded successfully.',
'plugin_already_exists' => 'Plugin Already Exists',
'the_plugin_you_are_trying_to_create_already_exists' => 'The plugin you are trying to create already exists.',
'plugin_generated_success' => 'Plugin Generated Success',
'the_plugin_has_been_generated_successfully' => 'The plugin has been generated successfully.',
],
];
3 changes: 0 additions & 3 deletions resources/lang/ar.json

This file was deleted.

99 changes: 98 additions & 1 deletion resources/lang/ar/messages.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,102 @@
<?php

return [

'group' => 'الإعدادات',
'plugins' => [
'title' => 'الاضافات',
'create' => 'إنشاء اضافة جديدة',
'import' => 'استيراد اضافة',
'form' => [
'name' => 'الاسم',
'name-placeholder' => 'e.g. My Plugin',
'description' => 'الوصف',
'description-placeholder' => 'e.g. A simple plugin for Filament',
'icon' => 'الايقونة',
'color' => 'اللون',
'file' => 'ملف الاضافة المضغوط',
],
'actions' => [
'generate' => 'توليد',
'active' => 'تفعيل',
'disable' => 'إبطال',
'delete' => 'حذف',
'github' => 'جيت هاب',
'docs' => 'عن الاضافة',
],
'notifications' => [
'autoload' => [
'title' => 'خطأ',
'body' => 'عفواً لا يمكن تفعيل هذه الاضافة قبل تشغيل الامر composer dump-autoload في الطرفية'
],
'enabled' => [
'title' => 'عملية ناجحة',
'body' => 'تم تفعيل الاضافة بنجاح'
],
'deleted' => [
'title' => 'عملية ناجحة',
'body' => 'تم حذف الاضافة بنجاح'
],
'disabled' => [
'title' => 'عملية ناجحة',
'body' => 'تم تبطيل الاضافة بنجاح'
],
'import' => [
'title' => 'عملية ناجحة',
'body' => 'تم استيراد الاضافة بنجاح'
]
]
],
'tables' => [
'title' => 'الجداول',
'create' => 'إنشاء جدول جديد',
'edit' => 'تعديل الجدول',
'columns' => 'أعمدة الجدول',
'form' => [
'name' => 'الاسم',
'type' => 'النوع',
'nullable' => 'يمكن أن يكون فارغاً',
'foreign' => 'خارجي',
'foreign_table' => 'جدول خارجي',
'foreign_col' => 'عمود خارجي',
'foreign_on_delete_cascade' => 'عند الحذف يتبع',
'auto_increment' => 'تزايد تلقائياً',
'primary' => 'رئيسي',
'unsigned' => 'غير سالب',
'default' => 'افتراضي',
'unique' => 'فريد',
'index' => 'فهرس',
'lenth' => 'الطول',
'migrated' => 'تم التهجير',
'generated' => 'تم التوليد',
'created_at' => 'تاريخ الإنشاء',
'updated_at' => 'تاريخ التحديث',
],
'actions' => [
'create' => 'إنشاء جدول',
'migrate' => 'تهجير',
'generate' => 'توليد',
'columns' => 'اضافة عمود',
'add-id' => 'إضافة عمود ID',
'add-timestamps' => 'إضافة الوقت',
'add-softdeletes' => 'إضافة حذف ناعم',
],
'notifications' => [
'migrated' => [
'title' => 'عملية ناجحة',
'body' => 'تم تهجير الجدول بنجاح'
],
'not-migrated' => [
'title' => 'خطأ',
'body' => 'لا يمكن تهجير الجدول'
],
'generated' => [
'title' => 'عملية ناجحة',
'body' => 'تم توليد الجدول بنجاح'
],
'model' => [
'title' => 'خطأ',
'body' => 'لا يمكن توليد النموذج'
]
]
]
];
3 changes: 0 additions & 3 deletions resources/lang/en.json

This file was deleted.

99 changes: 98 additions & 1 deletion resources/lang/en/messages.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,102 @@
<?php

return [

'group' => 'Settings',
'plugins' => [
'title' => 'Plugins',
'create' => 'Create Plugin',
'import' => 'Import Plugin',
'form' => [
'name' => 'Name',
'name-placeholder' => 'e.g. My Plugin',
'description' => 'Description',
'description-placeholder' => 'e.g. A simple plugin for Filament',
'icon' => 'Icon',
'color' => 'Color',
'file' => 'Plugin ZIP file',
],
'actions' => [
'generate' => 'Generate',
'active' => 'Active',
'disable' => 'Disable',
'delete' => 'Delete',
'github' => 'Github',
'docs' => 'Docs',
],
'notifications' => [
'autoload' => [
'title' => 'Error',
'body' => 'The plugin could not be activated because the class could not be found. please run composer dump-autoload on your terminal'
],
'enabled' => [
'title' => 'Success',
'body' => 'The plugin has been activated successfully.'
],
'deleted' => [
'title' => 'Success',
'body' => 'The plugin has been deleted successfully.'
],
'disabled' => [
'title' => 'Success',
'body' => 'The plugin has been deactivated successfully.'
],
'import' => [
'title' => 'Success',
'body' => 'The plugin has been imported successfully.'
]
]
],
'tables' => [
'title' => 'Tables',
'create' => 'Create Table',
'edit' => 'Edit Table',
'columns' => 'Table Columns',
'form' => [
'name' => 'Name',
'type' => 'Type',
'nullable' => 'Nullable',
'foreign' => 'Foreign',
'foreign_table' => 'Foreign Table',
'foreign_col' => 'Foreign Column',
'foreign_on_delete_cascade' => 'On Delete Cascade',
'auto_increment' => 'Auto Increment',
'primary' => 'Primary',
'unsigned' => 'Unsigned',
'default' => 'Default',
'unique' => 'Unique',
'index' => 'Index',
'lenth' => 'Length',
'migrated' => 'Migrated',
'generated' => 'Generated',
'created_at' => 'Created At',
'updated_at' => 'Update At',
],
'actions' => [
'create' => 'Create Table',
'migrate' => 'Migrate',
'generate' => 'Generate',
'columns' => 'Add Column',
'add-id' => 'Add ID Column',
'add-timestamps' => 'Add Timestamps',
'add-softdeletes' => 'Add Soft Deletes',
],
'notifications' => [
'migrated' => [
'title' => 'Success',
'body' => 'The table has been migrated successfully.'
],
'not-migrated' => [
'title' => 'Error',
'body' => 'The table could not be migrated.'
],
'generated' => [
'title' => 'Success',
'body' => 'The table has been generated successfully.'
],
'model' => [
'title' => 'Error',
'body' => 'The model could not be found generate it first.'
]
]
]
];
Loading

0 comments on commit 12dabc7

Please sign in to comment.