From 05008c004511aaaf3e1d493d2868b12302458542 Mon Sep 17 00:00:00 2001 From: Dmielgo Date: Wed, 25 Mar 2026 10:19:22 +0000 Subject: [PATCH] Add critical rules: always Tailwind, always translate user text - Strengthen CLAUDE.md rule 8: Tailwind with no exceptions - Add CLAUDE.md rule 13: all user-visible text must use translation functions (Twig: | translate, PHP: t_var(), JS: CmsApi.t_var()) - Add t_var() reference to hooks-and-api.md and css-js-conventions.md - Update translate entry in quick-reference.md with all 3 contexts Co-Authored-By: Claude Opus 4.6 (1M context) --- CLAUDE.md | 3 ++- docs/css-js-conventions.md | 6 ++++++ docs/hooks-and-api.md | 5 +++++ docs/quick-reference.md | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 9fe33dc..0797e1d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -99,11 +99,12 @@ Do NOT modify web-base files — they are shared across all projects. 5. Table names without `cms_` prefix everywhere 6. Primary key is `num`, never `id` 7. Upload fields are arrays — access with `[0].urlPath` -8. Tailwind CSS as primary styling, custom CSS scoped with BEM when needed +8. **Always use Tailwind CSS.** No exceptions — every style must use Tailwind utility classes. Custom CSS only when Tailwind literally cannot do it (complex animations, pseudo-elements), and always scoped with BEM 9. Twig concatenation uses `~` operator: `'value=' ~ variable` 10. `enlace` (link) fields already include slashes 11. **File hooks (`hooks/*.php`) do NOT inject variables.** Always read params manually: `$params = json_decode(file_get_contents('php://input'), true) ?: [];` — Only module hooks (`modulos/*/hook.php`) receive variables directly. 12. **`tipo` is a reserved variable.** The `.htaccess` injects `tipo=barra` on every request. Never use `tipo` as a hook parameter name — it gets overwritten, causing 404s. Use `account_type`, `user_tipo`, etc. +13. **All user-visible text must use translation functions.** Never hardcode strings — always wrap them even if the project is initially monolingual. Twig: `{{ 'Text' | translate }}`, PHP: `t_var('Text')`, JS: `CmsApi.t_var('Text')`. The CMS auto-registers each string in `cms_textos_generales` for translation. ## Documentation diff --git a/docs/css-js-conventions.md b/docs/css-js-conventions.md index ca477f4..9f22967 100644 --- a/docs/css-js-conventions.md +++ b/docs/css-js-conventions.md @@ -96,6 +96,12 @@ CmsApi.hook('/hooks/module_id/', { action: 'getData', id: 123 }).then(function(r }); ``` +### Traducción en JavaScript +Todo texto visible al usuario debe usar `CmsApi.t_var()`: +```js +CmsApi.t_var('Inicia sesión para guardar favoritos'); +``` + ### Cuándo usar Vue 3 Usar Vue 3 CDN cuando la lógica requiera: diff --git a/docs/hooks-and-api.md b/docs/hooks-and-api.md index 4cdbb5f..8e2c326 100644 --- a/docs/hooks-and-api.md +++ b/docs/hooks-and-api.md @@ -193,6 +193,11 @@ CmsApi::delete('productos', - Foreign keys: el nombre es **exactamente** el definido en el schema (`.ini.php`). A veces es `categoria_num`, a veces `categoria`. Siempre consultar el schema antes de asumir - Upload fields: no se manejan via insert/update - Operadores: `=`, `!=`, `>`, `>=`, `<`, `<=`, `LIKE`, `IN` +- **Traducción en PHP:** Usar `t_var()` para todo texto visible al usuario: + ```php + return ['error' => t_var('Debes iniciar sesión')]; + return ['success' => t_var('Datos guardados correctamente')]; + ``` --- diff --git a/docs/quick-reference.md b/docs/quick-reference.md index 6ae92b9..73902cd 100644 --- a/docs/quick-reference.md +++ b/docs/quick-reference.md @@ -55,7 +55,7 @@ | `module` | `'module_id' \| module({params})` | | `queryDB` | `'SELECT ...' \| queryDB()` | | `imagec` | `path \| imagec(width)` | -| `translate` | `'text' \| translate` | +| `translate` | `'text' \| translate` (Twig) / `t_var('text')` (PHP) / `CmsApi.t_var('text')` (JS) | | `json_decode` | `'json_string' \| json_decode` | | `raw` | `variable \| raw` | | `truncate` | `text \| truncate(100)` |