Change translation language programmatically - typo3

I've got a small problem with a TYPO3 extension.
The extension is translated in english and german (default is german) and I now need to switch the language programmatically.
Reason: We got some cronjobs running that create files using the language selected by the user for certain tasks (e.g. creating bills).
I am using TYPO3 6.x with Extbase and Fluid.

In your cronjob, change the language of the current backend user. You can use the $GLOBALS['BE_USER'] variable to access this. It has a property for the language. However, you might need to reinitialize the language service. How a look into the bootstrap to see how this is done.

Related

What is the relation between extensions and the backend of TYPO3?

I am new to TYPO3 and have trouble understanding the general relation between extensions and the backend of TYPO3.
For example, is it true that the goal of making an extension is to be able add edited/new content elements to your page that cannot be found in TYPO3 out of the box?
For example if I wanted to add a carousel to my page, would I make an extension and design it in such a way that I can add it from my backend to the desired page? Or would it make more sense to, for example, put it as a partial and import it to the desired page using fluid (all of this without using the backend and just using code).
Or are both approaches possible and when would you go for the first or the second (or seek out a third approach)?
Sorry if this question is too general/vague. I feel like I do not understand how the backend and the files in my TYPO3 folder communicate to generate the website and that I am using content elements in the backend one time and typing out the elements in HTML the next time without a good reason for it.
I try to bring some light into the dark areas.
Backend This is the admin area of the CMS where in most cases the content is created by editors.
Frontend: How the website looks to a regular visitor
Extension: An extension is custom code, either your own code or by others which extend TYPO3 in one or more ways. The benefit is that you don't change the code of TYPO3 core itself and therefore it can be always updated.
An extension can be used for a lot of things:
- Shipping a site template with all the assets like CSS, JavaScript, HTML template, ..
- Providing custom content elements
- Providing new record types like news or forms
- Improve user experience
So yes, if you want to have a new kind of content elements you need to use an extension:
Search on https://extensions.typo3.org to check if there is already something which fits your needs
Use https://extensions.typo3.org/extension/mask/ (best in combination with https://extensions.typo3.org/extension/mask_export/) or https://extensions.typo3.org/extension/dce/ to make it a lot faster to create content elements
If experienced you can also create a custom content elements without any additional extension but for start I don't recommend that.
One approach to look at this question in a different way might be to differentiate between content created and maintained by editors (the backend users which typically add and maintain content) and parts of the visible webpages created in other ways. For example, the header, footer, menu of a site may be created by a sitepackage extension - this is something the editor (backend user without admin access) typically has no permission to access and that is one of the points of a CMS - the content is editable by someone without technical background. Of course this improves the stability as well because you don't have people fiddling around with things they should not be able to have access to and thus cannot break.
If you want your editors to be able to add (remove, change) content - do it in a way they have access to (typically using content elements).
You are right, the core provides content elements (such as "textmedia"), extensions can extend this by adding other content elements.
For your example with "carousel" you might want to look at the (official) Introduction Package which uses the bootstrap_package which offers a carousel content element. The Installation Guide explains how to setup a TYPO3 installation with "Introduction Package" so you may already be using that.
For example, is it true that the goal of making an extension is to be able to add edited/new content elements to your page that cannot be found in TYPO3 out of the box?
That is one of many, many other possible purposes of an extension. For example, look at the extension "min". It does not provide any content element and there is no visible change for the editor. An extension is just a way to extend the TYPO3 core (while the core itself also consists of extensions).
Introduction of Extensions in TYPO3 Explained
Sitepackage Tutorial

Using Moodle APIs to change strings in activity plugin

In my Moodle activity plugin I am trying to allow an admin to change strings from the settings of the plugin. The strings that should be changeable are: Teacher, Class and Student . These are used throughout my plugin.
.
I am currently attempting it using php constants and that is working.
I am undecided if this is the the best method as I am converting an old plugin and not sure what string APIs I could use for Moodle 3.5.
Should I just proceed with the current method as it is working ?
If you use the standard Moodle handling for language strings (i.e. store them in [plugin]/lang/en/[nameofplugin].php and retrieve them with get_string() ), then an admin can override them by visiting Site admin > Language > Customise language pack.
That would be the normal way to allow for strings to be modified by admins (which would also allow for the words to be correctly handled in contexts, e.g. having the correct gender for the displayed language, handling plurals, etc.)

Form content in multiple languages: View behaviour and model handling

Currently I work an an app where the user can create products for a catalog. The status is, he can do this in one language, data gets send to the backend and saved. The next step would be to make this creation process ready for multiple languages e.g. english or french. The behaviour should be the following, he choses the language inside a drop down field and gets a form in the selected language.
The problems I encountered and my solution process till now:
1) How should the view handling be? Should I create a new fragment for every language and exchange the content? If Im correct that would mean I would need to destroy and create fragements for the languages, right? And then create them with a binded model again.
2) How should I handle the model/models? Should I create one model with the data they share e.g. creation date and create a model with language related attributes? That would be my solution right now.
Maybe you already did something similiar or have some thoughts about this, thanks for any help!
You should do neither of those things. There are mechanisms in place, generally referred to as i18n that help you with this process. UI5 help available here:
https://ui5.sap.com/sdk#/topic/df86bfbeab0645e5b764ffa488ed57dc
and
https://ui5.sap.com/sdk#/topic/5424938fc60244c5b708d71b50a0eee4
In summary, translations should be done using the i18n mechanisms and the oData logon language.
Logging into the application, assuming it's hosted on an SAP gateway or SCP / Launchpad, the user's current logon language will drive at least all standard SAP translatable texts like the labels returned from data elements in your oData services. The appropriate url parameter is sap-language=EN, but it's set automatically from the current browser settings. Generally, you don't have to worry about this.
The same browser settings drive which particular i18n file is loaded. This could be specific like en_US for American English, or fr for French.
If you code your app without any hard coded translations but always follow the rules in the links above, adding a language should be trivial.
These translations could probably be triggered programmatically via a dropdown as well but I have never tried that since it's extra steps for my users.

How to add an unsupported interface language to my iPhone app?

I have an iPhone app with interface languages in Toki Pona and Dothraki, which do not have ISO 639-3 codes. According to the ISO 639-3 standard, you can use the range qaa-qtz to represent languages for local use, which I have done (Toki Pona = qtp, Dothraki = qdt), but still get the warning from XCode "Unrecognized Locale".
It seems like I might be able to extend the main bundle class, but looking over the documentation, nothing seems to relate to adding non-ISO languages. I'm also aware of the text "If necessary, you can use a language or locale code that is not known to the NSBundle class or Core Foundation bundle functions. For example, you could create your own language designators for a language that is not yet listed in the ISO conventions or available as a language in Xcode." at the end of https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html
In any case, I mostly want to get rid of this warning. Any help would be greatly appreciated!
https://forums.swift.org/t/proposal-ns-locale-identifiers-etc-should-have-custom-types/9367/8
have a look at the above link.
Check if the languages are added as Localizations
I believe I have a solution however slightly complicated one. You would need to create a setting option within the app to use those made up languages and to load them manually from a file when a user sets them. For example, let's say your app consists of one label and the user sets the option to the made-up language you would call a method to set the language and the text on that label would update accordingly. I don't know whether this makes sense to you?? Basically, if the user uses the made-up languages that would override any system localization they have. It is doable it would just take time to implement it.

Create "multilanguage" site without redundant text in typo3

I'm not a big typo3 expert nor have I access to typoscript options at the typo3 instance I'm working with (It's a very big site and I don't have the authorization to do so). So I hope this question fits on stackoverflow (Please don't hate me if it does not, I'll happily post this on another site)
What I'm trying to achieve is:
My website has two possible translations (German and English). I see
that it's possible to switch languages during surfing through
clicking the "German"/"English"-Button
On the website are also informations about our staff (who may not be speaking german)
If one staff member doesn't speak german, I copy redundantly their english profile on the german translation mode (that it appears, because otherwise it doesn't - might be no good style, but it's better than not having them appear at all)
I'm not happy with these kind of redundancy since it means that I have to do the same action twice on the exactly same content. Does there exist a possibility in the backend of typo3 where I can set that the german translation shall be the exact same as the english content?
I hope my question is clear, thanks a lot for your help.
As you say you don't have access to typoscript templates etc, I guess you are not an integrator/developer in this project, but an editor.
Your only way to achieve an automatic "fallback" behaviour is asking the person who takes care of the site's configuration to set that up for you.
But if that's not possible, you can still use the "insert records" content element (german: "Datensatz einfügen") to avoid duplicate entries.
This content type is not in the wizard when you create a new content element. But you can create a text element and then change the type to "insert records". Now you can select another record which is then mirrored here:
You'll have a similar amount of work when setting it up, but you won't have redundant text, which is way better.
If this content type isn't available either, I would insist on the administrator enabling it for editors - it's very useful to maintain a site's content healthy.
Would be helpful to see your TypoScript configuration. Maybe theres something wrong with the sys_language_mode. Given that the sys_language_uid of english is 0 (which means its default language) and german is 1, the default behaviour should be, that german translations are shown, if available. If a translation is not available the default version of a content element is shown. However, you can change this behaviour with Typoscript:
config.sys_language_mode = content_fallback ; 5,3,1
This will set the content fallback of an content element (which is triggered if no translation exists) to sys_language_uid 5, if its not available in that language sys_language_uid 3 will be displayed etc.
Maybe your installation is set to
config.sys_language_overlay = hideNonTranslated
This will hide non-translated content-elements. Remove this entry to enable content fallback again.
You can always check the current Typoscript in the Template module via the TypoScript Object Browser. However, to really get help you need to share your TypoScript language configuration. The behaviour you describe is not the default behaviour, so its configured somewhere.