amaterasu

amaterasu

I have an umbrella project with N apps, all with the same web structure, but different db and possibly language.

Since the templates are all the same, I thought of creating a common app and I’m using templates like this:

defmodule WebEnglish.CategoryHTML do
  use WebEnglish, :html

  embed_templates "category_html/*", root: Common.Templates.root()
end

...

defmodule WebSpanish.CategoryHTML do
  use WebSpanish, :html

  embed_templates "category_html/*", root: Common.Templates.root()
end

I’m now having two issues:

  • I can’t use verified routes from common modules that are not templates, since sigil_p is not available there.
  • I can use verified routes in templates within common, but what if I need routes in another language/format? ex. ~p"/categories" works, but in WebSpanish this should be ~p"/categorias".

I’m looking at localized routes, but this wouldn’t work either because my understanding is that both categories and categorias would be valid routes in both my web apps.

So I kind of need Router Helpers again, but I know it’s deprecated and I’m looking for an alternative.
What do you think? Thanks!

Showing Posts 1 to 10

sodapopcan

sodapopcan

You can just import them assuming it all uses the same router. Recent Phoenix generators even give you a function to do so:

use MyAppWeb, :verified_routes

Take a look in your lib/my_app_web.ex file to see what that does (look for def verified_routes).

I have no experience localizing Elixir apps yet but there is this project which is by @kip so it’s gotta be good :slight_smile:

amaterasu

amaterasu OP

I can’t do that because MyAppWeb inside Common changes (it’s either WebEnglish or WebSpanish).

sodapopcan

sodapopcan

Ah right. Router helpers would have the same problem, though. Do you separate routers for each language are only one? If you have two then I’m not sure what the answer is here. If you have one then you can still use verified routes.

amaterasu

amaterasu OP

Router helpers work, I can do this in the WebEnglish.router function (same for spanish):

 use Phoenix.Router, helpers: true
 import WebEnglish.Router.Helpers

And in my templates (which are in the Common app):

<a href={category_path(@conn, :index)}>Categories</a>

To answer your question: yes, routers are separate per app (since the url structure and/or the languages are different).

sodapopcan

sodapopcan

Oh interesting, so the WebEnglish router helpers also work with the Spanish routes?

amaterasu

amaterasu OP

No, no, I have to duplicate that snippet in WebSpanish, too.

sodapopcan

sodapopcan

Can you give an example of how you are hoping a shared template will look? Your whole second question of “what if I need routes in another language” is I guess where I’m also confused.

I think you may want to look how the project I linked does it because I don’t think having one web module per language is the best course of action, even if you are only ever going to have two of them. If you do want to have two, I can’t really think of a better way than creating macros that check which module they are in and return the appropriate routes. This would be a 1-1 macro to routes, though which means basically you’d essentially have a third place to manage routes. Maybe someone else will have a better idea. If I think of anything else I’ll report back!

amaterasu

amaterasu OP

I’d like my template to look like this:

<a href={category_path(@conn, :index)}>Categories</a>

So, basically, I’d like the helper back :slight_smile: As stated before, this works and I know I can use it now, but it’s deprecated and I was wondering if there was an alternative.

Sorry about the misunderstanding with languages: my project has a single template for many frontends. They don’t necessarily have different languages, but they’re deployed separately and have their own db. The only thing in common are templates. Routes may or may not be different for the same entities, that’s why I need separate routers.

BartOtten

BartOtten

After reading the thread I am not sure I understand but let’s kick the can…

I think you don’t necessarily want helpers back but want to be able to write a path in your templates which translates during runtime to an URL depending on certain criteria.

Have a look at GitHub - BartOtten/routex: Build powerful Phoenix routes: localize, customize, and innovate · GitHub. Unlike native verified routes, Routex Verified Routes does support branching. As Routex is extension based, I am quite sure there is a combination of extension which will support your use case.

Demonstration
of single path in template with variable path during runtime

source code
demo page

amaterasu

amaterasu OP

Thank you, this looks really promising!

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews