@@ -203,6 +218,7 @@ function prepareEditForm(cat) {
document.getElementById('categoryAction').value = 'edit_category';
document.getElementById('categoryId').value = cat.id;
document.getElementById('categoryName').value = cat.name;
+ document.getElementById('categoryNameAr').value = cat.name_ar || '';
document.getElementById('categoryDescription').value = cat.description || '';
if (cat.image_url) {
@@ -213,7 +229,47 @@ function prepareEditForm(cat) {
document.getElementById('categoryImagePreview').style.display = 'none';
}
}
+
+document.getElementById('btnTranslate').addEventListener('click', function() {
+ const text = document.getElementById('categoryName').value;
+ if (!text) {
+ alert('Please enter a category name first.');
+ return;
+ }
+
+ const btn = this;
+ const originalHtml = btn.innerHTML;
+ btn.disabled = true;
+ btn.innerHTML = '
';
+
+ fetch('../api/translate.php', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ text: text,
+ target_lang: 'Arabic'
+ }),
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.success) {
+ document.getElementById('categoryNameAr').value = data.translated_text;
+ } else {
+ alert('Translation failed: ' + (data.error || 'Unknown error'));
+ }
+ })
+ .catch(error => {
+ console.error('Error:', error);
+ alert('An error occurred during translation.');
+ })
+ .finally(() => {
+ btn.disabled = false;
+ btn.innerHTML = originalHtml;
+ });
+});
-
+
\ No newline at end of file
diff --git a/db/migrations/030_add_name_ar_to_categories.sql b/db/migrations/030_add_name_ar_to_categories.sql
new file mode 100644
index 0000000..6b65467
--- /dev/null
+++ b/db/migrations/030_add_name_ar_to_categories.sql
@@ -0,0 +1,2 @@
+-- Add Arabic name to categories table
+ALTER TABLE categories ADD COLUMN name_ar VARCHAR(255) AFTER name;
diff --git a/pos.php b/pos.php
index 229b26a..9c4f423 100644
--- a/pos.php
+++ b/pos.php
@@ -156,12 +156,19 @@ if (!$loyalty_settings) {
@@ -173,7 +180,7 @@ if (!$loyalty_settings) {