I want to create my own translation file. For Example I want a "my-application.en_EN.yml" in my tranlsations folder in Ressources in my Bundle.
When I do this, the translation in my file does not work.
Only when I name the file like the standard name "messages.en_EN.yml" then it works.
But how can I have my own namings?
messages.{language}.yml is the default name of translation files (in YML format), Symfony will load the translation file automatically and provide translations in all the contexts.
It's different if the translation file has a different name, in this case you have to add the first part of the file name (the translation domain) as an argument when translating a string:
In a Controller:
$this->get('translator')->trans('my.message', array(), 'my-application');
In a Twig template:
{{ 'my.message'|trans({}, 'my-application') }}
See the official documentation for further information:
Translations (The Symfony Book)
The Translation Component (The Symfony Components)
Related
In my website -- Add screen/UI from which user can add translation dynamically
for example:
I want to add translation for "Hello World!" in multiple language and want to fetch according to language selection
Key :
strHelloWorld
Value:
Hello World!
Language:
en (it can be anything english,spanish,german etc)
This above 3 field data we can add/enter from Scree/UI by superadmin and
store/save in whatever form is good it can be in database or in json file
Please suggest way to add translation from screen
Asp.Net has a special file called resource files (.resx) to define the default locale (English) and other language texts.
For that please follow the steps:
step 1: You need to create .resx(resource file) into Resource(new
folder). create the file for the default language and second file with other lang.
step 2: set access modifier to public otherwise the
variable value will not appear on the view side
step 3: enter the variable name in the same in both files but make value different related to language.
step 4: once you declare the same variable name in both languages resource file, you can use that variable name where ever you want to declare in .cshtml file.
ex. Resources.Global.APP_NAME
For reference :
http://www.codedigest.com/posts/53/create-multi-language-website-in-aspnet-mvc---localization
Please use below nuget package
It is really awesome thanks to nuget and their author
https://github.com/RickStrahl/Westwind.Globalization
Please note that In this solution they have provided solution for all .net framwork/platform like asp.net 4.5 also aspnet core
Thanks again
I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.
How can I load data from yml files onto a HUGO template? I am having trouble understanding the documentation, what would be the steps?
I am using the hyde template.
Given a Yaml-file named mydata.yml:
Put this file into the folder /data inside your Hugo project. If it doesn't exist, create it. The exact name is important.
From the template you can then access the Yaml file as a data structure with $.Site.Data.mydata. Nested elements can be accessed by so called dot chaining: $.Site.Data.mydata.author.name
I have files named en_US.po, ru_RU.po etc.
Editing *.po files in PoEdit is very useful, but not while adding new strings manually.
How can I easily add new translation strings which are not automatically detected by PoEdit?
You can edit *.po files in any text editor and then in POEdit generate *.mo file
You misunderstand how gettext translations work. Source strings for translation are extracted from source code. It doesn't make sense to add them manually — they would never be used if they didn't have corresponding source code that uses them.
So the way to add strings is to use xgettext or Poedit's update from sources functionality.
P.S. The name's Poedit, not PoEditor.
You can configure your project (*.po file) opened in PoEdit. If you will done that correct PoEdit automatically update what to translate in this opened *.po file.
First of all, open *.po file which you want update with strings to
translate.
Go to Catalog -> Properties then to Source Paths tab
Add paths where PoEdit should look for source files in Your applilcation. More universal is to use relative to opened *.po file main path. If you have typical zf2 skeleton application folder structure you can add ../../.. for main path and add one module path.
Then go to Source of keywords tab and add translate and if you're using zf2 forms it is useful to add addLabel keyword (PoEdit will scan sources for this functions and add string parameters from them to your *.po file, as string to translate)
Next open Edit -> Preferences and in Processing programs tab, edit PHP section and add *.phtml extension (this will be scanned by poedit also)
After that you have to click in Update button and PoEdit will start scan your sources for strings to translate. Then you only have to do is translate found strings.
I followed this tutorial http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/ where Hello World is translated into German. If I want to translate Hello World to other language. Do I have to create another message.po and messge.mo file or I can add another translation in the same file or there's another way?
Normally you create one .po file per language, and split them up in different directories based on the locale name (like locale/de_DE/ in the tutorial), then you just use the specific file for the chosen locale as text domain in your implementation.