Tower : Localizing with an unanticipated dictionary - web

I'm working with the Tower library for i18n and l10n in my web application.
I have the problem of having to localize "just-in-time", i.e with an unanticipated dictionary, and in particular unanticipated supported locales.
I receive HTTP request, from which I can extract the accepted locales in preference order, e.g :
[:de :en-UK :en :fr-FR :fr]
On the other hand, I have to localize from micro-dictionaries which are fetched from a database, in the form :
{:fr "En Français"
:en "In English"
:en-Uk "In English from UK"}
What I would like to do in my program is to find the best matching translations from these 2 elements (in the example, it is :en-UK; note that I may not know in advance that :de is unavailable).
I haven't found a way to do that with the Tower library (and I'd like to avoid reinventing the wheel).
Does anyone know how I might proceed?
Thanks in advance!

Just added native support for arbitrary locale fallbacks in Tower v2.1.0-SNAPSHOT, as per discussion here: https://github.com/ptaoussanis/tower/issues/43#issuecomment-42014418
So it'll now be possible to request a translation like (t [:fr-FR :en-US] :example/foo).
Cheers! :-)

You could get a sequence of keys from the map, get all the values that are common to both sequences, and then choose whatever one is preferred based on whatever logic fits your requirements.

Related

FPC/Lazarus component like TImageList, but for generic files?

Just like TImageList contains a collection of images, is there a similar component for generic files?
I know I can embed files as resources, but I'd like the convenience of storing different groups of files in different "TFileList" components, and to be able to retrieve files by name or by their position in the list.
Extra points if such a component allowed some sort of design time preview of the file content (just like TImageList lets you see what each image looks like, at design time).
(I come from Delphi where I wrote my own component to do the above, but before I rewrite and port the property editor and all that to Lazarus, maybe there is already something that is tried and tested...)
Thanks!
You can use pre-defined lazarus TFPGList to specialize list of the type, that you want, for example - UTF8String
But, there's no T<>List as a component, only as object.
So, yes, this feature will be useful and i can implement, if have time,
also, there's a very limited RTTI, which has been updated only a few months ago, so you can access Methods and Properties now, so FP is more systemized, than delphi pascal, but also not so enterprise-developed, which limits it to implementations for common opensource and shareware project problems.
Nevertheless, it is more stable and supported, even my friends can contribute.

How to create custom abstract objects with attributes in Typo3?

I am now familiar with "basic" Typo3 - Usage and templating. Right now, I am stuck though, because I am not familiar with custom extensions etc.
I am looking for a way to represent Objects, that I get via methods of my own php-class from an XML-DB-Interface, in Typo3.
To be more precise :
I have a really complex XML-Interface and a php-class which is complete already, to interact with that interface, making methods available, that are meant to interact with different object-types in the underlying DB.
I now want to create abstract objects with the corresponding attributes in Typo3 to be able to work with them in typo3 (display/create/modify).
Furthermore, it would be helpful to find a way to "link" the functions of my php class to typo3-functions, so I can (perhaps?!) build up some kind of simple report-generator that generates conditional reports of those objects.
Could anybody lead me into the right direction and link (a) HowTo(s) or perhaps even examples that I could modify?
Thanks in advance, Oliver
Check how DBAL extension is coded.
https://docs.typo3.org/typo3cms/extensions/dbal/
You might want to implement this XML system as your own abstraction system to store your objects and use TYPO3 backend forms to manipulate those.

Search a specific search of a journal article based on the user type

I have this requirement:
We have a journalarticle and we wish to have sections which have content for internal and external users for the application.
We are able to hide the content from rendering by implementing custom template on web content display and using a simple custom-field for a user which helps us to classify it.
Having said that when we search something as an external user, the search portlet is able to fetch an article where the search text is a part of internal user content, and due to the above mentioned template the content is not visible.
In short, from the user's perspective the resultant article does not match the searched term.
I wish to seek some pointer to check whether there is a mechanism to ensure that when an external user searches something then we only search the dynamic-element of the doc which matches the user type?
We have thousands of such articles and create multiple copy of the same article does not seems viable solution.. so any pointers would be a great help.
Liferay version : 6.2 GA4 CE
Thanks!
AJ
First of all: Not finding a search term in a document can be a sign of good working synonym resolution in the search engine. It's questionable if this behaviour is always wrong or only in this particular case. Remember google bombs?
That being said, I believe that this architecture of half-visible documents is flawed from the beginning. Ideally I'd suggest to change it, for example by splitting the information to two articles, so that you can use the standard permissions to resolve. If you link both, you can determine how/which article or template to use. It's not an ideal solution, but might be a workaround.
Another workaround might be to change Liferay's indexer component and index two different versions of the article, with two different permissions. Of course, you'll have to change the search side as well, so that you'll find each article at most once, even if it's now twice in the search engine.
Again - not ideal, but might be the quickest fix that you can get right now without changing the underlying architecture. However, to change the underlying architecture is my actual recommendation.

Headers and pages in groovy

I'm converting a report written in SQR (old stuff) into groovy. SQR has a class that will allow you to specify a line-count, such that after that many lines of text are written to the report it will re-print the report header for you (as well as the page number that it keeps track of for you) so that when you go to the next page, the header is at the top of that page rather than a page or two back. Does groovy have anything like this?
Since Groovy itself is a generic language and not one for writing reports, the short answer is no.
You could try to find some java libraries that do what you want or at least support you. There are many many java libraries out there and Groovy is one of the JVM based languages that integrate really well with java lib. Maybe this SO answer is a starting point: https://stackoverflow.com/questions/6942247/i-need-some-java-reporting-engine
Also, be a bit more specific in your question. What is the target format for the report? Word, PDF or something else? What is a page in your case? etc...

Any way in Expression Engine to simulate Wordpress' shortcode functionality?

I'm relatively new to Expression Engine, and as I'm learning it I am seeing some stuff missing that WordPress has had for a while. A big one for me is shortcodes, since I will use these to allow CMS users to place more complex content in place with their other content.
I'm not seeing any real equivalent to this in EE, apart from a forthcoming plugin that's in private beta.
As an initial test I'm attempting to fake shortcodes by using delimited strings (e.g. #foo#) in the content field, then using a regex to pull those out and pass them to a function that can retrieve the content out of EE's database.
This brings me to a second question, which is that in looking at EE's API docs, there doesn't appear to be a simple means of retrieving the channel entries programmatically (thinking of something akin to WP's built-in get_posts function).
So my questions are:
a) Can this be done?
b) If so, is my method of approaching it reasonable? Or is there something stupidly obvious I'm missing in my approach?
To reiterate, my main objective here is to have some means of allowing people managing content to drop a code in place in their content that will be replaced with channel content.
Thanks for any advice or help you can give me.
Here's a simple example of the functionality you're looking for.
1) Start by installing Low Replace.
2) Create two Global Variables called gv_hello and gv_goodbye with the values "Hello" and "Goodbye" respectively.
3) Put this text into the body of an entry:
[say_hello]
Nice to see you.
[say_goodbye]
4) Put this into your template, wrapping the Low Replace tag around your body field.
{exp:low_replace
find="[say_hello]|[say_goodbye]"
replace="{gv_hello}|{gv_goodbye}"
multiple="yes"
}
{body}
{/exp:low_replace}
5) It should output this into your browser:
Hello
Nice to see you.
Goodbye
Obviously, this is a really simple example. You can put full blown HTML into your global variable. For example, we've used that to render a complex, interactive graphic that isn't editable but can be easily dropped into a page by any editor.
Unfortunately, due to parse order issues, EE tags won't work inside Global Variables. If you need EE tags in your short code output, you'll need to use Low Variables addon instead of Global Variables.
Continued from the comment:
Do you have examples of the kind of shortcodes you want to support/include? Because i have doubts if controlling the page-layout from a text-field or wysiwyg-field is the way to go.
If you want editors to be able to adjust layout or show/hide extra parts on the page, giving them access to some extra fields in the channel, is (imo) much more manageable and future-proof. For instance some selectfields, a relationship (or playa) field, or a matrix, to let them choose which parts to include/exclude on a page, or which entry from another channel to pull content from.
As said in the comment: i totally understand if you want to replace some #foo# tags with images or data from another field (see other answers: nsm-transplant, low_replace). But, giving an editor access to shortcodes and picking them out, is like writing a template-engine to generate ee-template code for the ee-template-engine.
Using some custom fields to let editors pick and choose parts to embed is, i think, much more manageable.
That being said, you could make a plugin to parse the shortcodes from a textareas content, and then program a lot, to fetch data from other modules you want to support. For channel entries you could build out of the channel data library by objectiveHTML. https://github.com/objectivehtml/Channel-Data
I hear you, I too miss shortcodes from WP -- though the reason they work so easily there is the ubiquity of the_content(). With the great flexibility of EE comes fewer blanket solutions.
I'd suggest looking at NSM Transplant. It should fit the bill for you.
There is also a plugin called Shortcode, which you can find here at
Devot-ee
A quote from the page:
Shortcode aims to allow for more dynamic use of content by authors and
editors, allowing for injection of reusable bits of content or even
whole pieces of functionality into any field in EE

Resources