I have an item in my mod declared like this:
public static final RegistryObject<Item> BLUE_SMALL_CARPET = Registration.ITEMS.register("blue_small_carpet", () -> new Item(new Item.Properties().tab(ItemGroup.TAB_DECORATIONS)));
I'm assigning a ranslation to it like this:
{
"item.smallcarpet.blue_small_carpet": "Blue Small Carpet"
}
(smallcarpet is the modid)
The translation doesn't show up in the game though.
Rename the file from en-us.json to en_us.json.
It seems to use this format la_ng.json (Source).
Related
i what to know more about SwiftUI, so i decided to make my own functionBuilder.
I made something like this:
public static func buildBlock<Content>(_ contents: Content...) -> Content {
return CombinedContent(with: contents)
}
And it works as expected
But i can't understand what should i do with buidIf function.
Does it should takes optional content and if it's nil return empty View or something?
I would also like to know how does it works under all this abstractions.
Thanks
I am building a native Xamarin app, and I am using Mvvmcross to do it. It is a really nice tool but I am still learning about how it works.
I found in the documentation yould could do the following thing with binding:
local:MvxBind="Text Format('Line: {0}', Line.Name)"
Here your binding the Testclass.Name variable with the format, so the result will be
Line: TestName
Now I want to do the same thing but also taking in a count the translation for Line:. So normally for translation you do the following.
local:MvxLang="Text Line_Label"
So my idea was to do something like this:
local:MvxLang="Text Format('{0}{1}', Line_Label, Line.Name)"
But it doesn't work like this. Does anybody have an idea if this is possible yet and how?
Use Tibet binding with local:MvxBind. Let's assume, that you have:
BaseViewModel.cs
public abstract class BaseViewModel : MvxViewModel
{
public IMvxLanguageBinder TextSource
{
get
{
return new MvxLanguageBinder(
Constants.GeneralNamespace,
GetType().Name);
}
}
}
MainViewModel.cs inheriting from BaseViewModel, with string property Name:
public string Name => "Radek";
TextProviderBuilder like in Stuart's N+1 days (no. 21) https://www.youtube.com/watch?v=VkxHtbJ_Tlk
JSON translation file with "MyLabel" key
{
"MyLabel" : "Your name:"
}
Answer: Then Android layout axml file will contain binding
local:MvxBind="Text Language(TextSource,'MyLabel') + ' ' + Name; Click NextCommand"
I don't know how to do this with local:MvxLang but the code above does the job :)
Suppose I have a task class MyTask which reads an input file, does some conversion on it and writes an output file (build.gradle):
class MyTask extends DefaultTask {
#InputFile File input
#OutputFile File output
String conversion
#TaskAction void generate() {
def content = input.text
switch (conversion) {
case "lower":
content = content.toLowerCase()
break;
case "upper":
content = content.toUpperCase()
break;
}
output.write content
}
}
project.task(type: MyTask, "myTask") {
description = "Convert input to output based on conversion"
input = file('input.txt')
output = file('output.txt')
conversion = "upper"
}
Now this all works fine, when I change input.txt or remove output.txt in the file system it executes again.
The problem is that it doesn't execute if I change "upper" to "lower", which is wrong.
I can't (don't want to) put build.gradle in the inputs list because that would be a hack, also wouldn't work if, say, a command line argument changes what gets into the myTask.conversion field. Another one I thought of is to write the value into a file in a setConversion() method and put that on the inputs list, but again, that's a hack.
How can I make gradle notice the change the official way? Also if you know where can I read more about this, don't hold back on links ;)
I read More about Tasks and Writing Custom Plugins, but it gave me no clue.
There is a handy #Input annotation, which is the same as Opal's answer (check its source code), but little more concise:
#Optional #Input String conversion
Here's a Gradle goodness article about this.
Not sure if it's helpful but I'd try:
class MyTask extends DefaultTask {
#InputFile File input
#OutputFile File output
String conversion
#TaskAction void generate() {
def content = input.text
switch (conversion) {
case "lower":
content = content.toLowerCase()
break;
case "upper":
content = content.toUpperCase()
break;
}
output.write content
}
void setConversion(String conversion) {
this.inputs.property('conversion', conversion)
this.conversion = conversion
}
}
Could you please check it?
So I'm using a language file in Titanium to serve TSS properties I want to re-use throughout the entire app at different locations. These language file variables should be used in the themes folder (or any other TSS file for that matter).
Currently it works with a single language, but my app has multiple languages. But I don't want to duplicate the language file for all languages. Can I re-use the same file in multiple languages without having to copy the file somewhere?
Use i18n files at ISO 639-1
representation.
That files allow you have any languages and use each "labels" with Ti.Locale.getString().
Also, you can use a require of file at app.js and put this variable like global.
language.js (for example):
var language = (function() {
var self = {
currentLanguage: 'en' // by default
};
var labels = {
msgHello: {
en: 'Hello World',
es: 'Hola Mundo'
}
};
self.changeLanguage = function changeLanguage(newLanguage){
self.currentLanguage = newLanguage;
};
self.getLabel = function getLabel(key, language){
if(typeof language !== 'undefined') {
return labels[key][language];
}
else return labels[key][self.currentLanguage];
};
return self;
}());
module.exports = language;
app.js (for example):
var appLanguage = require('language.js');
(function() {
Ti.API.info("Language: "+appLanguage.currentLanguage);
Ti.API.info("MSG Hello World (English): "+appLanguage.getLabel(msgHello));
Ti.API.info("MSG Hello World (Spanish): "+appLanguage.getLabel(msgHello, es));
}());
You can use appLanguage variable directly on any file.
It appears it is not possible to reuse a language file without copying it to all languages. However, the best solution to create a global go-to for parameters to be used in TSS files is to add a section to the config.json file.
A proper way to do this is:
"global": {
"design": {
"primaryColor": "red"
}
},
This can then be used by accessing Alloy.CFG.design.primaryColor.
The benefit for using the config.json file is that you can also theme the files, as described by Fokke Zandbergen.
This way, it is even better than using language files, because those couldn't be themed.
No, but you could use default strings like:
L('my_string','my default for this string');
In this example 'my_string' is a string withing your language file. If you only provide a file for English, you'll get the default setting for all other languages.
R
I'm trying to use ASP.Nets BundleTable to optomize some javascript files, but have run into a problem where a specific addon (jQuery-Timepicker) fails to work when the code has been minified. See here.
Bundle code is currently similar to:
// Add our commonBundle
var commonBundle= new Bundle("~/CommonJS" + culture.ToString());
// JQuery and related entries.
commonBundle.Include("~/Scripts/jquery-1.7.2.js");
commonBundle.Include("~/Scripts/jquery-ui-1.8.22.js");
commonBundle.Include("~/Scripts/jquery.cookie.js");
commonBundle.Include("~/Scripts/jquery-ui/jquery-ui-timepicker-addon.js"); // This is the one that does not work when bundled
// JS Transformer
commonBundle.Transforms.Add(new JsMinify());
BundleTable.Bundles.Add(commonBundle);
If I remove the jquery-ui-timepicker-addon.js file, then include it separate in my webpage, then it works properly. (Otherwise I get the Uncaught TypeError: undefined is not a function error).
I'm wondering if I can somehow setup my bundling code to skip minifying this one file (but still have it included in the bundle)? I've been looking around but have not come up with any solutions for doing so.
So the issue is that all the files are bundled together, and then the entire bundle is minimized. As a result you aren't going to easily be able to skip minification of just one file. Probably the best way to do this would be to create a new Transform that appended the contents of this file you want unminified. Then you would append this Transform to your registered ScriptBundle:
commonBundle.Transforms.Add(new AppendFileTransform(""~/Scripts/jquery-ui/jquery-ui-timepicker-addon.js""));
AppendFileTransform would simply append the contents of the file to the bundled response. You would no longer include the timepicker in the bundle explicitly, but instead this transform would be including it, and this would effectively give you the behavior you are looking since the JsMinify transform would run first and minify the bundle, and then you would add the file you want at the end unminified.
This can be solved better from the other direction - instead of trying to not minify a single file, add transforms for individual items instead.
First - create a class that implements IItemTransform and uses the same code to minify the given input:
public class JsItemMinify : System.Web.Optimization.IItemTransform
{
public string Process(string includedVirtualPath, string input)
{
var min = new Microsoft.Ajax.Utilities.Minifier();
var result = min.MinifyJavaScript(input);
if (min.ErrorList.Count > 0)
return "/*minification failed*/" + input;
return result;
}
}
Second - add this item transform to the individual files and remove the bundle transform:
var commonBundle= new Bundle("~/CommonJS");
// the first two includes will be minified
commonBundle.Include("~/Scripts/jquery-1.7.2.js", new JsItemMinify());
commonBundle.Include("~/Scripts/jquery-ui-1.8.22.js", new JsItemMinify());
// this one will not
commonBundle.Include("~/Scripts/jquery.cookie.js");
// Remove the default JsMinify bundle transform
commonBundle.Transforms.Clear();
BundleTable.Bundles.Add(commonBundle);
You cannot setup Bundle to skip minifying certain files and to minify rest of the files.
You could implement your own Bundle or Transform by overriding Bundle.ApplyTransform or JsMinify.Process methods, but you would need to take care not to break change-tracking of files, key generation, cache invalidation, etc... (or doing some ugly hack). It's not worth the effort.
I would keep separate js file, as you already mentioned.
This is just complete example based on Hao Kung's answer
var myBundle = new ScriptBundle("~/bundles/myBundle").Include(
"~/Scripts/script1.js",
"~/Scripts/script2.js",
);
myBundle.Transforms.Add(new AppendFileTransform("~/Scripts/excludedFile.min.js"));
bundles.Add(myBundle);
And here is example implementation of the AppendFileTransform:
public class AppendFileTransform : IBundleTransform
{
private readonly string _filePath;
public AppendFileTransform(string filePath)
{
_filePath = filePath;
}
public void Process(BundleContext context, BundleResponse response)
{
response.Content += File.ReadAllText(context.HttpContext.Server.MapPath(_filePath));
}
}