Laravel 9 - Can you use nested Folders with Lang Directories? - localization

To make my project support localisation for both frontend views and with Controllers for notifications/warnings etc I was considering nesting the lang files in a mirrored structure as the views themselves?
For example my view of:
app/resources/views/user/profile.blade.php
Would have a lang file of:
app/resources/lang/en/user/profile.php
Now lets say my lang file simply contains a title:
<?php
return [
'title'=>"Welcome to Your Profile",
]
?>
And my profile.blade.php simply contains this. I have attempted to access the profile.title as follows but it just displays:
<h2 class="page-title mb-0">{{__('user.profile.title')}}</h2>
<h2 class="page-title mb-0">'user.profile.title</h2>
Is this possible, I've attempted to Google this approach but all the examples I could find don't mention this but I would assume larger apps systems would need this to make localisation manageable?

From my continued research into this it appears you cannot have a set of nested folders of configs and be able to access it as I queried above.
The format works the exact same way as the config so you could have a file user.php and have an array of profile containing a key of title and access it like this:
{{__('user.profile.title)}}
It just means if you have a complex system you will end up with a lot of files or few large ones.

Related

How to create dynamic lists in 11ty static site generator?

I'm creating a new website, and I want to be able to edit my content using Vim. That means I should probably be using a static site generator - right? I've been using Drupal for the last ten years, but since I don't need to give clients a gui to edit their content, I'm considering a different technology.
11ty looks like a decently simple static site generator, and the ability to type my content in markdown in Vim, run a simple command, git commit and push to publish the content is very appealing.
But I'm wondering about more dynamic/automated content... like in Drupal there are "views" which are SQL queries (and can be quite complex, it provides a gui for building them and formatting their results) for displaying recent posts, upcoming events, etc. How do you create such elements in 11ty? Can 11ty alone do it? Would you have to utilize something like vue.js with 11ty to do this?
I'd be open to using a different static site generator (I'm even considering using Drupal and posting to the site's Rest API) but I don't want to deal with reactjs.
The heart and soul of processing "data" in 11ty is putting things into .json or .js files that export a JavaScript object into the _data folder of your project.
Let's say you have a file in there called kittens.js like this:
const kittens = [
{
name: 'Oreo',
colors: ['black','white'],
slug: 'oreo'
},
{
name: 'Hershey',
colors: ['brown'],
slug: 'hershey'
}
];
module.exports = () => {
return kittens;
};
The keyword kittens is now a special keyword as far as 11ty template files capable of having a "page" context is concerned.
It contains the nested-object-structured information about Oreo and Hershey.
All you have to do is pick a templating language and loop through it.
For example, you could put a file into your project's main folder called, say, loop_kittens.liquid like this, and 11ty would pick it up as something from which it's supposed to generate HTML:
---
layout: "layouts/my_base"
pagination:
alias: documentData
data: kittens
size: 1
addAllPagesToCollections: true
permalink: /kitten/{{ documentData.slug }}/index.html
---
<h1>{{documentData.name}}</h1>
<ul>
{% for color in documentData.colors %}
<li>color</li>
{% endfor %}
</ul>
I'm not familiar with Drupal, but the #1 thing you're going to have to deal with in coming from any declarative SQL-based (table-shaped) system and moving into an imperative nested-lists-and-objects-shape-based system is thinking about looping through data and selecting it differently.
You may even want to preprocess your raw data in those _data-folder files so that it gets exported to kittens in a way that's optimized for rather traditional manual for-looping (although the "pagination" properties of a template with size set to 1 can definitely help hide the complexities of dividing up a dataset into individual HTML pages that need generation).
11ty pagination can also "chunk" your dataset so that you only have to worry about hand-looping through a given subchunk of kittens on any given page (e.g. the "kitten archives," with 10 kittens per archive page).
But as far as actually putting a block for each kitten on each of those pages -- that's going to be a manual for-loop in your template, whichever templating language you choose. (I've found that Liquid strikes a nice balance between simplicity and being able to delegate things in each pass of a for loop to an "include," so as to maintain modular, componentized code -- see "dynamic partials".)
I recommend making your own dummy data like I just did and practicing using all of 11ty's many templating, layout, component-include, etc. options on a practice site before you start trying to do a real project. 11ty isn't a very opinionated framework, so it's nice to pick your own favorite way of organizing it and learning about its magic-folder naming conventions.

Can I keep all my external links in a separate file with Sphinx?

I have a Sphinx project with a collection of files that contain external links as references at the bottom of each file like this:
Some text with `my link`_, more text
100 lines of text ...
.. _my link: http://example.com
I'd like to reorganize my files, splitting them, merging them and reusing external links. To make this easier, I'd like to keep my links in a separate file, each one with a unique id that I can reference in the text. Is there a way to do this? The rendered output should still create an external link, not a footnote like it was suggested in How do I collect all external links in Sphinx?
This can be solved with the right settings in conf.py:
# Exclude link file
exclude_patterns = ['_build', 'links.rst']
# make rst_epilog a variable, so you can add other epilog parts to it
rst_epilog =""
# Read link all targets from file
with open('links.rst') as f:
rst_epilog += f.read()
links.rst looks like this:
.. _my link: http://example.com
.. _my other link: http://example2.com
With this setup, I'm flexible to use either the unique ID as the link label or provide a custom link label:
Some text with `my link`_ and a `custom label<my other link>`_

Grails internationaliization with custom bundles

My Grails (2.4.2) app was created with a bunch of "default/standard" resource bundles:
myapp/
grails-app/
i18n/
messages.properties
messages_fr.properties
I would now like to create my own "custom" resource bundle, that is, define properties in a file outside of these standard messages*.properties files that myapp was created with.
According to the i18n documentation, all bundles need to be prefixed with messages and suffixed .properties. So I added two new props files, one for English and one for French:
myapp/
grails-app/
i18n/
messages.properties
messages_fr.properties
messages_myapp.properties
messages_myapp_fr.properties
For one, I'm not 100% sure I'm interpreting the docs correctly. So if anything about my 2 new props files jumps out at you as being incorrect, please start by letting me know!
Having said that, in all the example from those docs, I don't see where you specify the bundle to use. All of the examples look like this:
<g:message code="fizz.buzz.foo" />
But what if I have a fizz.buzz.foo property defined in both messages_blah.properties and messages_bar.properties?
So I ask: How do I add my own custom resource bundles, and how do I properly refer to them from inside a GSP?
To answer your question you have to understand what Grails (well, Spring really) is doing to accomplish this.
You are on the right path with the multiple files. What you have outlined there matches the documentation and will work.
However, under the covers what is really being done is they are being combined into a single bundle (per language). So there is no need to tell Grails/Spring which bundle to use.
Finally, what happens when the same key is defined multiple times? The first one matched wins. I seem to recall that the order in which the bundles are combined is in file name order, though you should be able to test this pretty quickly.
Hope this helps, and best of luck!

How are chapters handled in Typo3 Neos?

I want to use chapters and chapter-menu as a e.g. image gallery, reference module or other collections in Typo3 Neos.
As there are multiple domains with different content in my installation i have a problem with the NodeTypes.yaml:
All my site packages are based on NeosDemoTypo3Org. Because i don't want to have multiple entries "chapter", "chapter menu", "youtube" and so on, i deleted the NodeTypes.yaml in my copies of NeosDemoTypo3Org (which is still installed).
When i add a page with content element "chapter menu" to a package and put some chapters in it, the chapter overview is only displayed, if am putting the NodeTypes.yaml back into my package configuration. But then again i have multiple entries of the same thing.
How/where can i configure this to fit my needs?
That should be no problem. Just having the Chapter etc. in one NodeTypes.yaml is enough for now (until we implemented separation per Site which we want to have at some point). But I guess you adapted all occurances of "TYPO3.NeosDemoTypo3Org" in your TypoScript to match the new package name? You need to of course change that back for everything that is related to those NodeTypes. The TypoScript must point to the correct name for this NodeType. And you have to declare the TypoScript in each package because TypoScript is NOT shared in contrast to the NodeTypes.
What you could do is create a "base package" that contains the NodeTypes and TypoScript (and Tempaltes for those) and include the TypoScript in each of your Site packages.

I can't find where a string is getting defined -- any tricks to find its source?

I'm using:
Rails 3.2x
Spree 1.2
Ruby 1.9.3x
I'm trying to edit the title of one of my pages, and I cannot find where it is getting defined. It is showing up in my base ERB file as 'title', but that name is sufficiently generic to make it next to impossible to find where it is defined.
I have prodded everywhere I can think, I've tried searching for "title =", but nothing is working. I tried calling source_location on it, but that appears to only work on methods.
Any tricks for finding where a variable is defined?
I can't think of an elegant way. A dumb-but-probably-effective way would be to dump stack trace in your erb, then see what those locations are doing and if title is defined there. It has to enter somewhere between the start of program and invoking your erb.
When I can't find something, I use grep -ri some_string . at the command-line to recursively search all the content of the directory.
It's also a good tactic to let your editor search all the source code, since the ones worth using have the ability to search through all files in a directory.
it is created from a mixture of product names, a site config, and something else
An alternate trick is to add a HTML-comment section in your ERB file, and put the pertinent information for the components used to create the title into that section. Then, let the pages be generated and look inside the page's content to determine what table and row ID it is, the site_config filename, etc.
You really should be able to figure it out based on the parts that are concatenated to build the title and then search your database or files. That information isn't magically created out of thin air by Rails; Someone had to tell Rails how to define the title. But, people move on, or they don't document correctly, so try the embedded information trick.

Resources