[IMP] website_sale_aplicoop: improve i18n label fallbacks and response parsing

Add hardcoded fallback translations for es/eu when PO-based translation
returns the source string unchanged. Expand labels dict with all keys
needed by the frontend. Fix JSON response parsing in template
(data.result || data). Add js_translations keys. Add pot file for
stock_picking_batch_custom.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
GitHub Copilot 2026-05-25 12:28:33 +02:00
parent 647438e012
commit 5eea3e2a23
7 changed files with 346 additions and 20 deletions

View file

@ -43,15 +43,89 @@ def _get_translated_labels(self, lang=None, request_obj=None):
lang = _get_detected_language(self, request_obj=req)
env_lang = req.env(context=dict(req.env.context, lang=lang))
lang_code = (lang or "").split("_")[0]
fallbacks = {
"es": {
"Browse Product Categories": "Explorar categorías de productos",
"Save Draft": "Grabar pedido",
"Save order as draft": "Grabar pedido",
"Order saved as draft": "Pedido grabado",
"This order's cart is empty.": "El carrito de este pedido está vacío.",
"This order's cart is empty": "El carrito de este pedido está vacío",
},
"eu": {
"Browse Product Categories": "Produktu kategoriak arakatu",
"Save Draft": "Eskaera gorde",
"Save order as draft": "Eskaera gorde",
"Order saved as draft": "Eskaera gordeta",
"This order's cart is empty.": "Eskaera honen saskia hutsik dago.",
"This order's cart is empty": "Eskaera honen saskia hutsik dago",
},
}
def tr(source):
translated = env_lang._(source)
if translated == source:
translated = fallbacks.get(lang_code, {}).get(source, translated)
return translated
labels = {
"product": env_lang._("Product"),
"quantity": env_lang._("Quantity"),
"price": env_lang._("Price"),
"subtotal": env_lang._("Subtotal"),
"total": env_lang._("Total"),
"empty": env_lang._("This order's cart is empty."),
# ... keep minimal set here; website_sale.py will fall back if needed
"product": tr("Product"),
"quantity": tr("Quantity"),
"price": tr("Price"),
"subtotal": tr("Subtotal"),
"total": tr("Total"),
"empty": tr("This order's cart is empty."),
"empty_cart": tr("This order's cart is empty."),
"browse_categories": tr("Browse Product Categories"),
"all_categories": tr("Browse Product Categories"),
"save_draft": tr("Save Draft"),
"save_order_as_draft": tr("Save order as draft"),
"order_saved_as_draft": tr("Order saved as draft"),
"save_cart": tr("Save Cart"),
"reload_cart": tr("Reload Cart"),
"proceed_to_checkout": tr("Proceed to Checkout"),
"confirm_order": tr("Confirm Order"),
"back_to_cart": tr("Back to Cart"),
"remove_item": tr("Remove Item"),
"cancel": tr("Cancel"),
"confirm": tr("Confirm"),
"confirmation": tr("Confirmation"),
"items": tr("items"),
"items_placeholder": tr("items"),
"added_to_cart": tr("added to cart"),
"cart_restored": tr("Your cart has been restored"),
"order_loaded": tr("Order loaded"),
"invalid_quantity": tr("Please enter a valid quantity"),
"connection_error": tr("Connection error"),
"error_unknown": tr("Unknown error"),
"error_saving_draft": tr("Error saving cart"),
"error_loading_draft": tr("Error loading draft"),
"error_processing_response": tr("Error processing response"),
"draft_saved": tr("Order saved as draft"),
"draft_saved_success": tr("Cart saved as draft successfully"),
"draft_loaded_success": tr("Draft order loaded successfully"),
"reload_draft_confirm": tr(
"Are you sure you want to load your last saved draft?"
),
"reload_draft_replace": tr("This will replace the current items in your cart"),
"reload_draft_with": tr("with the saved draft."),
"clear_cart_confirm": tr(
"Are you sure you want to clear the cart? This will also cancel any saved draft order."
),
"cart_cleared": tr("Cart cleared"),
"draft_cancelled": tr("draft order cancelled"),
"home_delivery": tr("Home Delivery"),
"delivery_information": tr("Delivery Information"),
"delivery_info_template": tr(
"Delivery Information: Your order will be delivered at {pickup_day} {pickup_date}"
),
"important": tr("Important"),
"confirm_order_warning": tr(
"Once you confirm this order, you will not be able to modify it. Please review carefully before confirming."
),
"pickup_day_label": tr("Pickup Day"),
}
return labels