Translations in indexed-search with own templates - typo3-8.x

I'm using Typo3 8.7.11 and the extension indexedSearch 8.7.11 with Fluid-Templates
I created an extension with my own fluid-templates for the search and search-results form.
Now I also want to use my own translations for these templates. So I created the following files in myTemplateExt/Resources/Private/Language:
locallang.xlf (for the default - en - language)
de.locallang.xlf
fr.locallang.xlf
it.locallang.xlf
Alas, the translations are not loaded.
I found out that I can add the whole path to the translations like
<f:translate key="LLL:EXT:myTemplateExt/Resources/Private/Language/locallang.xlf:sform.submit" />
But then only the locallang.xlf file is loaded. All other languages are ignored.
I also tried to add my own variable to the indexed-search TS-setup:
plugin.tx_indexedsearch.settings.langfile = EXT:myTemplateExt/Resources/Private/Language/locallang.xlf
Which of course fails miserably (most likely because I can't define my own settings-var in TS for another extension?)
Any ideas how I can make the indexed-search extension use my own lang-files?
P.S. I found this suggestion on StackOverflow:
Typo3 Indexed Search Local_Lang path
But this is not what I want - I need more flexibility for my templates, as I need to add some more text than just the regular keys that indexed-search provides to them (yeah, customers, you know ;)

It might not be the best solution, but I solved the problem like this:
I set a variable according to the current language:
<v:variable.set name="currentLang" value="{v:page.language(languages: 'LLL:EXT:myExt/Resources/Private/Language/de.locallang.xlf,
LLL:EXT:myExt/Resources/Private/Language/en.locallang.xlf,
LLL:EXT:myExt/Resources/Private/Language/fr.locallang.xlf,
LLL:EXT:myExt/Resources/Private/Language/it.locallang.xlf',
normalWhenNoLanguage: 'LLL:EXT:myExt/Resources/Private/Language/de.locallang.xlf')}" />
And then for the translation:
<f:form.submit name="search[submitButton]" value="{f:translate(key: '{currentLang}:sform.submit')}" id="tx-indexedsearch-searchbox-button-submit" class="tx-indexedsearch-searchbox-button" />
This isn't elegant, but it works...

Related

Symfony using multiple translation files for single language

I was wondering if it is possible with Symfony 3.5 to use multiple translation files for a single language when using yml files.
Currently I have something like this:
AppBundle/Resources/translations/messages.en.yml
AppBundle/Resources/translations/messages.de.yml
which contains all my translations in either language. However I was wondering if it was possible to change this to the following structure:
AppBundle/Resources/translations/en/products.yml
AppBundle/Resources/translations/en/invoices.yml
AppBundle/Resources/translations/de/products.yml
AppBundle/Resources/translations/de/invoices.yml
I have been looking but I have been unable to find some kind of solution for this. I got it working for splitting up my routes.
AppBundle/Resources/config/routing.yml
appbundle_routes:
resource: '#AppBundle/Resources/config/routing'
type: directory
Inside that folder I got all my routes split like:
AppBundle/Resources/config/routing/products.yml
AppBundle/Resources/config/routing/users.yml
AppBundle/Resources/config/routing/invoices.yml
I was wondering if it was possible to achieve the same thing with translations?
Symfony's Translator requires files to by named in format domain.locale.loader. In case you have messages.en.yml:
messages is the default name of domain, you can also specify eg. invoices
en is the locale
yml is specifying YAML loader will be used
So your proposed use is not possible to achieve with standard set of configs and functionality. However, you can split your translations to different domain files. So paths would be:
AppBundle/Resources/translations/products.en.yml
AppBundle/Resources/translations/invoices.en.yml
And when you are using translator you specify the domain in which the translation should be looked for:
$translator->trans('translated.key', [], 'invoices');
Or in Twig:
{{ 'translated.key'|trans({},'invoices') }}

Meteor how to save templates in mongo

I want to give my users the possibility to create document templates (contracts, emails, etc.)
The best option I figured out would be to store these document templates in mongo (maybe I'm wrong...)
I've been searching for a couple of hours now but I can't figure out how to render these document template with their data context.
Example:
Template stored in Mongo: "Dear {{firstname}}"
data context: {firstname: "Tom"}
On Tom's website, He should read: "Dear Tom"
How can I do this?
EDIT
After some researches, I discovered a package called spacebars-compiler that brings the option to compile to the client:
meteor add spacebars-compiler
I then tried something like this:
Template.doctypesList.rendered = ->
content = "<div>" + this.data.content + "</div>"
template = Spacebars.compile content
rendered = UI.dynamic(template,{name:"nicolas"})
UI.insert(rendered, $(this).closest(".widget-body"))
but it doesn't work.
the template gets compiled but then, I don't know how to interpret it with its data context and to send it back to the web page.
EDIT 2
I'm getting closer thanks to Tom.
This is what I did:
Template.doctypesList.rendered = ->
content = this.data.content
console.log content
templateName = "template_#{this.data._id}"
Template.__define__(templateName, () -> content)
rendered = UI.renderWithData(eval("Template.#{templateName}"),{name:"nicolas"})
UI.insert(rendered, $("#content_" + this.data._id).get(0))
This works excepted the fact that the name is not injected into the template. UI.renderWithData renders the template but without the data context...
The thing your are missing is the call to (undocumented!) Template.__define__ which requires the template name (pick something unique and clever) as the first argument and the render function which you get from your space bars compiler. When it is done you can use {{> UI.dynamic}} as #Slava suggested.
There is also another way to do it, by using UI.Component API, but I guess it's pretty unstable at the moment, so maybe I will skip this, at least for now.
Use UI.dynamic: https://www.discovermeteor.com/blog/blaze-dynamic-template-includes/
It is fairly new and didn't make its way to docs for some reason.
There are few ways to achieve what you want, but I would do it like this:
You're probably already using underscore.js, if not Meteor has core package for it.
You could use underscore templates (http://underscorejs.org/#template) like this:
var templateString = 'Dear <%= firstname %>'
and later compile it using
_.template(templateString, {firstname: "Tom"})
to get Dear Tom.
Of course you can store templateString in MongoDB in the meantime.
You can set delimiters to whatever you want, <%= %> is just the default.
Compiled template is essentially htmljs notation Meteor uses (or so I suppose) and it uses Template.template_name.lookup to render correct data. Check in console if Template.template_name.lookup("data_helper")() returns the correct data.
I recently had to solve this exact (or similar) problem of compiling templates client side. You need to make sure the order of things is like this:
Compiled template is present on client
Template data is present (verify with Template.template_name.lookup("data_name")() )
Render the template on page now
To compile the template, as #apendua have suggested, use (this is how I use it and it works for me)
Template.__define__(name, eval(Spacebars.compile(
newHtml, {
isTemplate: true,
sourceName: 'Template "' + name + '"'
}
)));
After this you need to make sure the data you want to render in template is available before you actually render the template on page. This is what I use for rendering template on page:
UI.DomRange.insert(UI.render(Template.template_name).dom, document.body);
Although my use case for rendering templates client side is somewhat different (my task was to live update the changed template overriding meteor's hot code push), but this worked best among different methods of rendering the template.
You can check my very early stage package which does this here: https://github.com/channikhabra/meteor-live-update/blob/master/js/live-update.js
I am fairly new to real-world programming so my code might be ugly, but may be it'll give you some pointers to solve your problem. (If you find me doing something stupid in there, or see something which is better done some other way, please feel free to drop a comment. That's the only way I get feedback for improvement as I am new and essentially code alone sitting in my dark corner).

How to override template “folder_full_view_item.pt”?

This question is a reformulation of this question which had evolved in a confusing way. Please refer to this question if you search some in depth details or are interested in workarounds and alternative solutions.
This question is about the call to template folder_full_view_item.pt in folder_full_view.pt, not about other templates in general!
Please avoid workarounds like skin layers, editskinswitcher, etc. I don't want to solve a particular use case here. What I want is to really understand how this actually works.
I present this question in three parts: scenario, result, questions.
scenario
Have a Folder with a Document. The layout of the Folder is folder_full_view. The layout of the Document is document_view:
Folder (layout=folder_full_view)
Document (layout=document_view)
The template folder_full_view.pt calls template folder_full_view_item.pt via item.getObject().folder_full_view_item().
folder_full_view_item.pt calls (e.g. for a Document content type ) the template document_view.pt via use-macro="item_macro" (item_macro being something like here/document_view/macros/content-core). Schematically as follows:
folder_full_view.pt :: item.getObject().folder_full_view_item()
folder_full_view_item.pt :: use-macro="here/document_view/macros/content-core"
document_view.pt
In a plone3_theme have overriden versions of the templates folder_full_view.pt, folder_full_view_item.pt, and document_view.pt. These templates are registered as follows in configure.zcml.
<browser:page
for="*"
name="folder_full_view_item"
template="folder_full_view_item.pt"
layer="example.theme.browser.interfaces.IThemeSpecific"
permission="zope2.View"
/>
<browser:page
for="Products.ATContentTypes.content.folder.ATFolder"
name="folder_full_view"
template="folder_full_view.pt"
layer="example.theme.browser.interfaces.IThemeSpecific"
permission="zope2.View"
/>
<browser:page
for="Products.ATContentTypes.content.document.ATDocument"
name="document_view"
template="document_view.pt"
layer="example.theme.browser.interfaces.IThemeSpecific"
permission="zope2.View"
/>
results
With the theme installed the results are:
Document and Folder get their templates (I guess) via traversal. The (sub)templates though don't go through the traversal.
Folder: uses overriden folder_full_view.pt, original folder_full_view_item.pt, and original document_view.pt
Document: uses overriden document_view.pt
questions
is it the case that item.getObject().folder_full_view_item() doesn't go through traversal? If yes why?
what can be modified (in folder_full_view.pt!) to force a traversal to the overriden folder_full_view_item.pt(!) and subsequently to the overriden document_view.pt? Is this possible?
Again, please avoid workarounds like skin layers, editskinswitcher, etc. I don't want to solve a particular use case here. What I want is to really understand how this actually works.

ASP.NET How to use WebConfigurationManager to get section from Specific config file?

I am trying to get sections from specific .config file such like "my.config".
WebConfigurationManager.OpenWebConfiguration can get the web.config in specific path.
Maybe WebConfigurationManager.OpenMappedWebConfiguration can reach my purpose.
Can anyone share experience?
I don't know about using the OpenMappedWebconfig thing, but this is a way to do it using a easy utility class:
http://aspalliance.com/705
If you want to have neater access to the config, then create a custom class that inherits from ConfigurationSection, then you can access the variables using syntax like MyConfig.configkey, Here's an article that describes how to create the custom class and is good for some further info:
https://web.archive.org/web/20211020133931/https://www.4guysfromrolla.com/articles/032807-1.aspx
This article shows how to do internal custom config sections:
http://www.beansoftware.com/asp.net-tutorials/multiple-config.aspx
HTH,
Lance
EDIT: The aspalliance.com is down, so to tide you over, here are some other helpful links:
Here's a super-simple way to do it - http://www.codeproject.com/KB/files/custom_config_file_reader.aspx
Here's the verbose Microsoft way - http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

Changing the QTY label in Uber Cart?

How do you change the QTY (quantity) label in UberCart (in Drupal) without actually hacking the core components? I want the label to be be months, instead of qty.
You could use the String Overrides module. Here is an excerpt from its project page:
Provides a quick and easy way to replace any text on the site.
Features:
Easily replace anything that's passed through t()
Locale support, allowing you to override strings in any language
Ability to import/export *.po files, for easy migration from the Locale module
Note that this is not a replacement to Locale as having thousands of overrides can cause more pain then benefit. Use this only if you need a few easy text changes.
I once ran into a similar issue with Ubercart in another language (German), and we "solved" it by re-translating the string. The mentioned module should do the trick in your case.
I haven't used ubercarts, but I would guess there would be an admin section to do that. Else hook_form_alter() or hook_form_FORM_ID_alter() should be able to do the trick for you.
Unfortunately, there is no setting for this in ubercart.
Doing a search for 'Qty' (case sensitive, as there are numerous 'qty' in code) in the current ubercart-6.x-2.0-rc7 release gives seven matches:
3 in theme functions, which you'd need to override in your theme
1 in a form definition, which you'd need to change via hook_form_alter as googletorp suggested
3 in table definitions, which you'd need to change via hook_tapir_table_alter and/or hook_tapir_table_header_alter (see the hooks.php file in ubercarts doc directory for these)
So you should be able to implement your changes without changing the module itself, but given the amount of work involved, I'd try schnecks suggestion first ;)

Resources