Xamarin resource.id not found - xamarin.android

I've deleted the bin and obj files. I've cleaned it. Unloaded VS and loaded it back, still no change. I have other elements in the activity_main.xml file which are no problem. Just this one:
In compiling this Xamarin (C#) code I get an error that resource id/openTest (aka com.mytest.mytest2:id/openTest) not found.
in the activity_main.xml file I have the following:
<Button
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/my_button_selector"
android:focusable="false"
android:backgroundTint="#40000000"
android:text="Open"
android:id="#id/openTest"
android:layout_below="#+id/expandview"
android:layout_centerHorizontal="true" />
and in the MainActvity.cs file I have the following:
btnOpenTest.Click += delegate
{
openTest();
};
public void openTest()
{
}
If I comment out all the openTest related code the app compiles ok.

Related

How do you handle multiple application classes in a xamarin android project

There is a 3rd party library I need to use, that includes a class decorated with the [Application] attribute. This causes compiler errors since I have my own application class that uses an [Application] attribute. I would like my application class to inherit from the 3rd party lib's application class.
public class MyApplication : ThirdPartyApplication
{
}
however since I can't decorate my class with the [Application] attribute I have no way to specify in the Manifest that it should run "MyApplication" and not "ThirdPartyApplication".
If I manually add an entry into AndroidManifest.xml
<application
android:name="com.your.packagename.MyApplication"
android:icon="#drawable/luncher_icon"
android:label="#string/app_name">
It will get replaced after the project gets built with
<application
android:name="mdxxx.ThirdPartyApplication"
android:icon="#drawable/luncher_icon"
android:label="#string/app_name">
Does anyone know how to handle this situation in Xamarin Android?
Keep in mind that the 3rd party library can not be modified.
An alternate solution would be a way to disable all manifest generating attributes and manually create the AndroidManifest. There does not seem to be any way to do this either.
The below post is the exact situation I am having but in pure Android. Note that due to the above issues that this solution will not work for Xamarin.
how-to-handle-multiple-application-classes-in-android
So I was able to figure out a solution but it boarders on being a hack.
In short the android manifest is going to be modified using MSBuild.
Step 1: Have your custom application class inherit from the the Third Party lib's custom application and decorate your class with the "Register" tag.
[Register("com.namespace.MyApplication")]
public class MyApplication : ThirdPartyApplication
{
}
Step 2: Have your project include the RoslynCodeTaskFactory NuGet package
Step 3: Unload your project, then add the following in the Project tag
<UsingTask TaskName="UpdateManifest" TaskFactory="CodeTaskFactory" AssemblyFile="$(RoslynCodeTaskFactory)" Condition=" '$(RoslynCodeTaskFactory)' != '' ">
<ParameterGroup>
<AndroidManifestFilename ParameterType="System.String" Required="true" />
<ApplicationName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.Xml" />
<Code Type="Fragment" Language="cs"><![CDATA[
XmlDocument doc = new XmlDocument();
doc.Load(AndroidManifestFilename);
XmlNode node = doc.DocumentElement.SelectSingleNode("/manifest/application");
node.Attributes["android:name"].InnerText = ApplicationName;
doc.Save(AndroidManifestFilename);
]]></Code>
</Task>
</UsingTask>
<Target Name="CleanManifest" AfterTargets="_GenerateJavaStubs">
<UpdateManifest AndroidManifestFilename="$(ProjectDir)\obj\$(Configuration)\android\AndroidManifest.xml" ApplicationName="com.namespace.MyApplication" />
</Target>
Step 4: Reload the project and build. The manifest should now point to custom application class. If you get a class not found runtime exception most likely you forgot to add [Register] from Step 1.

Visual Studio (Xamarin): DependencyService + Nuget + iOS = Fail

We are writing a Visual Studio (Xamarin) cross-platform application that will share quite a bit of functionality with the next application we write, so we wanted to put that shared functionality into a "library" so we could test it, share it easily, etc.
The only way we found to write a cross-platform library, is to create it using the standard Xamarin DependencyService paradigm, turn it into a NuGet package, and then load that package into our main app. For better or worse, we did this before Microsoft provided a template for generating NuGet libraries like this, so we had to roll it ourselves.
This works fine for Android, but now I'd like to get the same code working for iOS and it's simply not working. No errors, no warnings, but when I run the app and call
Client = DependencyService.Get<IClient>();
It simply returns null. If I look at the Output/Debug window, it is loading the 'Company.Client.Abstractions.dll' (the root DLL containing the definition of IClient) but not the iOS-specific 'Company.Client.dll' (which contains the iOS-specific implementation of IClient).
Here's my nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>Client</id>
<version>0.0.35</version>
<authors>Me</authors>
<owners>Company</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Stuff</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright 2017 Company</copyright>
<dependencies>
<group targetFramework="MonoAndroid">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
<group targetFramework="Xamarin.iOS10">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
<group targetFramework="uap">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
</dependencies>
</metadata>
<files>
<!-- Cross-platform reference assemblies -->
<file src="Company.Client.Abstractions\bin\Debug\Company.Client.Abstractions.dll" target="lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Company.Client.Abstractions.dll" />
<file src="Company.Client.Abstractions\bin\Debug\Company.Client.Abstractions.pdb" target="lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Company.Client.Abstractions.pdb" />
<!-- iOS reference assemblies -->
<file src="Company.Client.iOS\bin\iPhone\Debug\Company.Client.dll" target="lib\Xamarin.iOS10\Company.Client.dll" />
<file src="Company.Client.iOS\bin\iPhone\Debug\Company.Client.pdb" target="lib\Xamarin.iOS10\Company.Client.pdb" />
<!-- Android reference assemblies -->
<file src="Company.Client.Android\bin\Debug\Company.Client.dll" target="lib\MonoAndroid10\Company.Client.dll" />
<file src="Company.Client.Android\bin\Debug\Company.Client.pdb" target="lib\MonoAndroid10\Company.Client.pdb" />
<!-- UWP reference assemblies -->
<file src="Company.Client.UWP\bin\Debug\Company.Client.dll" target="lib\UAP10\Company.Client.dll" />
<file src="Nuvectra.Client.UWP\bin\Debug\Company.Client.pdb" target="lib\UAP10\Company.Client.pdb" />
</files>
</package>
I'm thinking there are two classes of possible problems:
I'm generating the DLL wrong
I'm generating the application wrong
Looking at the generated DLLs, the Android DLL is 28k long, the iOS DLL is 23k, so it doesn't look like the iOS DLL is empty. Is there a tool that would let me inspect the iOS DLL and make sure it has the necessary entry point(s)?
The Project that generates the iOS DLL has these settings:
Target framework: Xamarin.iOS
Output type: Class Library
Condition compilation symbols: __ UNIFIED__;__ MOBILE__;__ IOS__
Platform: Active (Any CPU)
The application that is using the DLL has these settings for the iOS Project:
SDK Version: Default
Linker Behavior: Don't Link
Platform: Active (iPhone)
Supported Architectures: ARMv7 + ARM64
Target framework: Xamarin.IOS
Output type: Console Application
Conditional compilation symbols: __ UNIFIED__;__ MOBILE__;__ IOS__
The interface definition in my 'Abstractions' project looks like this:
namespace Company.Client
{
public abstract class IClient
{
void abstract function();
}
}
and the implementation in my iOS project looks like this:
using Company.Client.iOS;
[assembly: Xamarin.Forms.Dependency (typeof (IosClient))]
namespace Company.Client.iOS
{
public class IosClient : IClient
{
void override function();
}
}
We tried many different ways to create a NuGet package with platform-specific code loaded using DependencyService and every single way had the same problem - worked fine under Android, failed under iOS.
The solution is to create a class in the iOS library that is not loaded using DependencyService, and then in the iOS application, create an instance of that class. That's enough to convince the iOS application that it actually needs to load the iOS library DLL, and then the rest of the DependencyService magic works correctly.

MiniProfiler does not load

I installed Nuget package miniprofiler.com but the profiler windows is not visible, but the miniprofiler script was generated to the html.
I putted following script to the global.asax
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
To the _Layout.cshtml at first line
#using StackExchange.Profiling;
last lines
#MiniProfiler.RenderIncludes()
</body>
</html>
script generated
<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=ySF6M98CBehTtL86BbiEmys9yxR1HKazhe2sznfdUWQ=" data-version="ySF6M98CBehTtL86BbiEmys9yxR1HKazhe2sznfdUWQ=" data-path="/mini-profiler-resources/" data-current-id="d011005d-606a-4dca-a3a0-8e8654c344af" data-ids="74098d83-5d5f-4f2b-a3ab-1a7294dd4490,f6e7117a-81cf-4632-b30b-9f93ec0ebfbf,b0069a2b-68b3-4e58-a477-5529e780266c,d011005d-606a-4dca-a3a0-8e8654c344af" data-position="left" data-trivial="false" data-children="false" data-max-traces="15" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false" data-trivial-milliseconds="2"></script>
but I do not see the profiler window, what am I doing wrong ?!
I also tried totally new web project (mvc4) in visual studio and the problem is same.
I tried the exact steps as yours and the profiler window was not getting displayed.
I had to add a tag in the web.config file to get the profiler window to appear.
Use runAllManagedModulesForAllRequests="true" as shown below,
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>

temporarily Stop Bundling and minification [duplicate]

I have debug="true" in both my web.config(s), and I just don't want my bundles minified, but nothing I do seems to disable it. I've tried enableoptimisations=false, here is my code:
//Javascript
bundles.Add(new ScriptBundle("~/bundles/MainJS")
.Include("~/Scripts/regular/lib/mvc/jquery.validate.unobtrusive.js*")
.Include("~/Scripts/regular/lib/mvc/jquery.validate*")
.Include("~/Scripts/regular/lib/bootstrap.js")
.IncludeDirectory("~/Scripts/regular/modules", "*.js", true)
.IncludeDirectory("~/Scripts/regular/pages", "*.js", true)
.IncludeDirectory("~/Scripts/regular/misc", "*.js", true));
//CSS
bundles.Add(new StyleBundle("~/bundles/MainCSS")
.Include("~/Content/css/regular/lib/bootstrap.css*")
.IncludeDirectory("~/Content/css/regular/modules", "*.css", true)
.IncludeDirectory("~/Content/css/regular/pages", "*.css", true))
Conditional compilation directives are your friend:
#if DEBUG
var jsBundle = new Bundle("~/Scripts/js");
#else
var jsBundle = new ScriptBundle("~/Scripts/js");
#endif
If you have debug="true" in web.config and are using Scripts/Styles.Render to reference the bundles in your pages, that should turn off both bundling and minification. BundleTable.EnableOptimizations = false will always turn off both bundling and minification as well (irrespective of the debug true/false flag).
Are you perhaps not using the Scripts/Styles.Render helpers? If you are directly rendering references to the bundle via BundleTable.Bundles.ResolveBundleUrl() you will always get the minified/bundled content.
To disable bundling and minification just put this your .aspx file
(this will disable optimization even if debug=true in web.config)
vb.net:
System.Web.Optimization.BundleTable.EnableOptimizations = false
c#.net
System.Web.Optimization.BundleTable.EnableOptimizations = false;
If you put EnableOptimizations = true this will bundle and minify even if debug=true in web.config
You can turn off minification in your bundles simply by Clearing your transforms.
var scriptBundle = new ScriptBundle("~/bundles/scriptBundle");
...
scriptBundle.Transforms.Clear();
I personally found this useful when wanting to bundle all my scripts in a single file but needed readability during debugging phases.
I tried a lot of these suggestions but noting seemed to work. I've wasted quite a few hours only to found out that this was my mistake:
#Scripts.Render("/bundles/foundation")
It always have me minified and bundled javascript, no matter what I tried. Instead, I should have used this:
#Scripts.Render("~/bundles/foundation")
The extra '~' did it. I've even removed it again in only one instance to see if that was really it. It was... hopefully I can save at least one person the hours I wasted on this.
Combine several answers, this works for me in ASP.NET MVC 4.
bundles.Add(new ScriptBundle("~/Scripts/Common/js")
.Include("~/Scripts/jquery-1.8.3.js")
.Include("~/Scripts/zizhujy.com.js")
.Include("~/Scripts/Globalize.js")
.Include("~/Scripts/common.js")
.Include("~/Scripts/requireLite/requireLite.js"));
bundles.Add(new StyleBundle("~/Content/appLayoutStyles")
.Include("~/Content/AppLayout.css"));
bundles.Add(new StyleBundle("~/Content/css/App/FunGrapherStyles")
.Include("~/Content/css/Apps/FunGrapher.css")
.Include("~/Content/css/tables.css"));
#if DEBUG
foreach (var bundle in BundleTable.Bundles)
{
bundle.Transforms.Clear();
}
#endif
There is also some simple way to control minification (and other features) manually. It's new CssMinify() transformer using, like this:
// this is in case when BundleTable.EnableOptimizations = false;
var myBundle = new StyleBundle("~/Content/themes/base/css")
.Include("~/Content/themes/base/jquery.ui.core.css" /* , ... and so on */);
myBundle.Transforms.Add(new CssMinify());
bundles.Add(myBundle);
// or you can remove that transformer in opposite situation
myBundle.Transforms.Clear();
That's convenient when you want to have some bundles special part only to be minified. Let's say, you are using some standard (jQuery) styles, which are getting under your feet (taking lots of excessive browser requests to them), but you want to keep unminified your own stylesheet. (The same - with javascript).
I combined a few answers given by others in this question to come up with another alternative solution.
Goal: To always bundle the files, to disable the JS and CSS minification in the event that <compilation debug="true" ... /> and to always apply a custom transformation to the CSS bundle.
My solution:
1) In web.config:
<compilation debug="true" ... />
2) In the Global.asax Application_Start() method:
protected void Application_Start() {
...
BundleTable.EnableOptimizations = true; // Force bundling to occur
// If the compilation node in web.config indicates debugging mode is enabled
// then clear all transforms. I.e. disable Js and CSS minification.
if (HttpContext.Current.IsDebuggingEnabled) {
BundleTable.Bundles.ToList().ForEach(b => b.Transforms.Clear());
}
// Add a custom CSS bundle transformer. In my case the transformer replaces a
// token in the CSS file with an AppConfig value representing the website URL
// in the current environment. E.g. www.mydevwebsite in Dev and
// www.myprodwebsite.com in Production.
BundleTable.Bundles.ToList()
.FindAll(x => x.GetType() == typeof(StyleBundle))
.ForEach(b => b.Transforms.Add(new MyStyleBundleTransformer()));
...
}
If you set the following property to false then it will disable both bundling and minification.
In Global.asax.cs file, add the line as mentioned below
protected void Application_Start()
{
System.Web.Optimization.BundleTable.EnableOptimizations = false;
}
Here's how to disable minification on a per-bundle basis:
bundles.Add(new StyleBundleRaw("~/Content/foobarcss").Include("/some/path/foobar.css"));
bundles.Add(new ScriptBundleRaw("~/Bundles/foobarjs").Include("/some/path/foobar.js"));
Sidenote: The paths used for your bundles must not coincide with any actual path in your published builds otherwise nothing will work. Also make sure to avoid using .js, .css and/or '.' and '_' anywhere in the name of the bundle. Keep the name as simple and as straightforward as possible, like in the example above.
The helper classes are shown below. Notice that in order to make these classes future-proof we surgically remove the js/css minifying instances instead of using .clear() and we also insert a mime-type-setter transformation without which production builds are bound to run into trouble especially when it comes to properly handing over css-bundles (firefox and chrome reject css bundles with mime-type set to "text/html" which is the default):
internal sealed class StyleBundleRaw : StyleBundle
{
private static readonly BundleMimeType CssContentMimeType = new BundleMimeType("text/css");
public StyleBundleRaw(string virtualPath) : this(virtualPath, cdnPath: null)
{
}
public StyleBundleRaw(string virtualPath, string cdnPath) : base(virtualPath, cdnPath)
{
Transforms.Add(CssContentMimeType); //0 vital
Transforms.Remove(Transforms.FirstOrDefault(x => x is CssMinify)); //0
}
//0 the guys at redmond in their infinite wisdom plugged the mimetype "text/css" right into cssminify upon unwiring the minifier we
// need to somehow reenable the cssbundle to specify its mimetype otherwise it will advertise itself as html and wont load
}
internal sealed class ScriptBundleRaw : ScriptBundle
{
private static readonly BundleMimeType JsContentMimeType = new BundleMimeType("text/javascript");
public ScriptBundleRaw(string virtualPath) : this(virtualPath, cdnPath: null)
{
}
public ScriptBundleRaw(string virtualPath, string cdnPath) : base(virtualPath, cdnPath)
{
Transforms.Add(JsContentMimeType); //0 vital
Transforms.Remove(Transforms.FirstOrDefault(x => x is JsMinify)); //0
}
//0 the guys at redmond in their infinite wisdom plugged the mimetype "text/javascript" right into jsminify upon unwiring the minifier we need
// to somehow reenable the jsbundle to specify its mimetype otherwise it will advertise itself as html causing it to be become unloadable by the browsers in published production builds
}
internal sealed class BundleMimeType : IBundleTransform
{
private readonly string _mimeType;
public BundleMimeType(string mimeType) { _mimeType = mimeType; }
public void Process(BundleContext context, BundleResponse response)
{
if (context == null)
throw new ArgumentNullException(nameof(context));
if (response == null)
throw new ArgumentNullException(nameof(response));
response.ContentType = _mimeType;
}
}
To make this whole thing work you need to install (via nuget):
WebGrease 1.6.0+
Microsoft.AspNet.Web.Optimization 1.1.3+
And your web.config should be enriched like so:
<runtime>
[...]
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-x.y.z.t" newVersion="x.y.z.t" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-x.y.z.t" newVersion="x.y.z.t" />
</dependentAssembly>
[...]
</runtime>
<!-- setting mimetypes like we do right below is absolutely vital for published builds because for some reason the -->
<!-- iis servers in production environments somehow dont know how to handle otf eot and other font related files -->
<system.webServer>
[...]
<staticContent>
<!-- in case iis already has these mime types -->
<remove fileExtension=".otf" />
<remove fileExtension=".eot" />
<remove fileExtension=".ttf" />
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".otf" mimeType="font/otf" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
<!-- also vital otherwise published builds wont work https://stackoverflow.com/a/13597128/863651 -->
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
[...]
</system.webServer>
Note that you might have to take extra steps to make your css-bundles work in terms of fonts etc. But that's a different story.
Search for EnableOptimizations keyword in your project
So if you find
BundleTable.EnableOptimizations = true;
turn it false.
This does disable minification,
And it also disables bundling entirely
Just to supplement the answers already given, if you also want to NOT minify/obfuscate/concatenate SOME files while still allowing full bundling and minification for other files the best option is to go with a custom renderer which will read the contents of a particular bundle(s) and render the files in the page rather than render the bundle's virtual path. I personally required this because IE 9 was $*%#ing the bed when my CSS files were being bundled even with minification turned off.
Thanks very much to this article, which gave me the starting point for the code which I used to create a CSS Renderer which would render the files for the CSS but still allow the system to render my javascript files bundled/minified/obfuscated.
Created the static helper class:
using System;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
namespace Helpers
{
public static class OptionalCssBundler
{
const string CssTemplate = "<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />";
public static MvcHtmlString ResolveBundleUrl(string bundleUrl, bool bundle)
{
return bundle ? BundledFiles(BundleTable.Bundles.ResolveBundleUrl(bundleUrl)) : UnbundledFiles(bundleUrl);
}
private static MvcHtmlString BundledFiles(string bundleVirtualPath)
{
return new MvcHtmlString(string.Format(CssTemplate, bundleVirtualPath));
}
private static MvcHtmlString UnbundledFiles(string bundleUrl)
{
var bundle = BundleTable.Bundles.GetBundleFor(bundleUrl);
StringBuilder sb = new StringBuilder();
var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
foreach (BundleFile file in bundle.EnumerateFiles(new BundleContext(new HttpContextWrapper(HttpContext.Current), BundleTable.Bundles, bundleUrl)))
{
sb.AppendFormat(CssTemplate + Environment.NewLine, urlHelper.Content(file.VirtualFile.VirtualPath));
}
return new MvcHtmlString(sb.ToString());
}
public static MvcHtmlString Render(string bundleUrl, bool bundle)
{
return ResolveBundleUrl(bundleUrl, bundle);
}
}
}
Then in the razor layout file:
#OptionalCssBundler.Render("~/Content/css", false)
instead of the standard:
#Styles.Render("~/Content/css")
I am sure creating an optional renderer for javascript files would need little to update to this helper as well.
If you're using LESS/SASS CSS transformation there's an option useNativeMinification which can be set to false to disable minification (in web.config). For my purposes I just change it here when I need to, but you could use web.config transformations to always enable it on release build or perhaps find a way modify it in code.
<less useNativeMinification="false" ieCompat="true" strictMath="false"
strictUnits="false" dumpLineNumbers="None">
Tip: The whole point of this is to view your CSS, which you can do in the browser inspect tools or by just opening the file. When bundling is enabled that filename changes on every compile so I put the following at the top of my page so I can view my compiled CSS eaily in a new browser window every time it changes.
#if (Debugger.IsAttached)
{
View CSS
}
this will be a dynamic URL something like https://example.com/Content/css/bundlename?v=UGd0FjvFJz3ETxlNN9NVqNOeYMRrOkQAkYtB04KisCQ1
Update: I created a web.config transformation to set it to true for me during deployment / release build
<bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
<less xdt:Transform="Replace" useNativeMinification="true" ieCompat="true" strictMath="false" strictUnits="false" dumpLineNumbers="None">
<jsEngine name="MsieJsEngine" />
</less>
</bundleTransformer>
This may become useful to someone in the future as the new framework, when setup through VS, gets a default web.config, web.Debug.config and web.Release.config. In the web.release.config you will find this line:
<compilation xdt:Transform="RemoveAttributes(debug)" />
this was seeming to override any inline changes I made. I commented this line out and we were gravy (in terms of seeing non-minified code in a "release" build)

How to get the language specific messages using google closure template

Am trying to implement internationalization support to my project for this people suggested google Closure Templates.but am very new to closure templates.am trying to get the language specific messages using closure template but am not getting in xlf file.If any one knows how to generate language specific messages using closure template, please tell me the steps.that's great help to me.
My .soy file code as bellow.
{namespace poc}
/**
*Testing message translation
*#param pageTitle
*/
{template .translate}
<HTML>
<Head>
<title>{$pageTitle}
</title>
</head>
<div>
{msg desc="Hello"}Hello{/msg}
</div>
</html>
{/template}
and generated .xlf content as bellow
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="SoyMsgBundle" datatype="x-soy-msg-bundle" xml:space="preserve" source-language="en" target-language="pt-BR">
<body>
<trans-unit id="2286494898080570401" datatype="html">
<source>Thanks</source>
<target/>
<note priority="1" from="description">Says thanks</note>
</trans-unit>
</body>
</file>
</xliff>
I see you already used the SoyMsgExtractor to create the base xlf. Next you need to make translations of this base xlf to the languages you want to support. A file for each language is created. I used the xliff exitor from Translution. http://sourceforge.net/projects/eviltrans.
Next, using the SoyToJsSrcCompiler a translation soy can be made per language:
java -jar SoyToJsSrcCompiler.jar --shouldGenerateGoogMsgDefs --bidiGlobalDir 1 --messageFilePathFormat Filename_en-us.xliff --outputPathFormat FileName_fr.js *.soy
This will create a Filename._fr.js file that contains the compiled soy file.
Including this file instead of the original soy (or compiled) will create a localized version.
Good luck!
\Rene
i think the easiest way is to make (i.e. generate from whatever source) a separate js file which contains one messages object and reference it through an extern declared function.
it justs works and has no complicated dependencies.

Resources