I have a Qt app with a Czech translation. I can get my translation compiled and installed fine with the following code. But when I run the app, translation doesn't work. What am I missing?
I even tried to chmod 644 to change the permissions of the translation file, but it didn't work either.
Thanks in advance.
TRANSLATIONS += cs_CZ.ts
isEmpty(QMAKE_LRELEASE) {
win32|os2:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\lrelease.exe
else:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]/lrelease
unix {
!exists($$QMAKE_LRELEASE) { QMAKE_LRELEASE = lrelease-qt4 }
} else {
!exists($$QMAKE_LRELEASE) { QMAKE_LRELEASE = lrelease }
}
}
updateqm.input = TRANSLATIONS
updateqm.output = qm/${QMAKE_FILE_BASE}.qm
updateqm.commands = $$QMAKE_LRELEASE -silent ${QMAKE_FILE_IN} -q qm/${QMAKE_FILE_BASE}.qm
updateqm.CONFIG += no_link target_predeps
QMAKE_EXTRA_COMPILERS += updateqm
INSTALLS += translations
translations.path = /usr/share/app
translations.files = qm/cs_CZ.qm
Related
I am looking for a way to set the default locale for certain host servers.
Given the servername is server-spain, e.g. I would like to redirect by default to the spanish translation, preferably any page the user lands, besides browser settings. So by default, even the app language/locale is English by default, if accessing through website.es (spanish domain) the user will see spanish as default language.
$this['servername'] = gethostname(); // host name
{% if servername is same as('server-in-spain') %}
// reload with spanish locale
{% endif %}
Anybody found themselves in this situation? Anybody solved it?
Thanks!
You can add this code to your layout's code section and it should do the job.
use RainLab\Translate\Classes\Translator;
public function onStart() {
$translator = Translator::instance();
$currentLocale = $translator->getLocale();
$newLocale = 'es';
$translatedRedirect = false;
$servername = gethostname(); // <- YOUR FUNCTION TO FIND HOST
// MAKE SURE IF YOU DO NOT HAVE GIVEN LOCAE IN Backend
// THNE IT WILL REDIRECT TO DEFAULT SET LOCALE
if($servername === 'server-in-spain') {
$newLocale = 'es';
}
if($servername === 'server-in-germany') {
$newLocale = 'de';
}
// we do not want to redirect if user have already perfect locale
if($currentLocale !== $newLocale) {
$translatedRedirect = true;
}
if($translatedRedirect) {
$translator->setLocale($newLocale);
$currentUrl = $this->currentPageUrl();
$parts = parse_url($currentUrl);
$path = array_get($parts, 'path');
$pageUrl = http_build_url($parts, [
'path' => '/' . $translator->getPathInLocale($path, $newLocale)
]);
return Redirect::to($pageUrl);
}
}
It should do the job
if any doubt please comment
With Hardik's answer I could solve it.
The only issues I encountered with this solution were :
I wasnt able to select a different locale in a given domain. That is example.es , correctly displaying /es locale but unable to switch locales (as it was forced by the code)
I solved it with a first time cookie:
function onStart() {
//Set the cookie for firt time visit
$first_visit = !isset( $_COOKIE["fist_locale"] );
// Set the cookie so that the message doesn't show again
setcookie( "first_locale", 1, strtotime( '+1 week' ) );
if( $first_visit ){ // if user first time
$translator = Translator::instance();
$currentLocale = $translator->getLocale();
$newLocale = 'en';
$translatedRedirect = false;
$servername = gethostname(); // <- YOUR FUNCTION TO FIND HOST
// MAKE SURE IF YOU DO NOT HAVE GIVEN LOCAE IN Backend
// THNE IT WILL REDIRECT TO DEFAULT SET LOCALE
if($servername === 'example.es') {
$newLocale = 'es';
}
if($servername === 'example.de') {
$newLocale = 'de';
}
// we do not want to redirect if user have already perfect locale
if($currentLocale !== $newLocale) {
$translatedRedirect = true;
}
if($translatedRedirect) {
$translator->setLocale($newLocale);
$currentUrl = $this->currentPageUrl();
$parts = parse_url($currentUrl);
$path = array_get($parts, 'path');
$pageUrl = http_build_url($parts, [
'path' => '/' . $translator->getPathInLocale($path, $newLocale)
]);
return Redirect::to($pageUrl);
}
}//end of first time
}
The locale forced by the domain name function adds /(locale) after the domain as in example.de/de
Adding virtualisation.virtualbox.guest.enable = true; to the /etc/nixos/configuration.nix adds the VirtualBox Guest Additions to the resulting NixOS system, and creates a systemd service to run the VBoxService executable.
I want to use a different version of the guest additions than the one which "ships" with the current channel / nixpkgs.
So I tried to overwrite the package in configuration.nix using nixpkgs.config.packageOverwrites:
nixpkgs = {
config = {
allowUnfree = true;
packageOverrides = xpkgs: {
linuxPackages = xpkgs.linuxPackages //
(
let vbox = xpkgs.callPackage ./vbox-guest.nix { kernel = xpkgs.linuxPackages.kernel; };
in
{
virtualboxGuestAdditions = vbox;
kernel = xpkgs.linuxPackages.kernel // {virtualboxGuestAdditions = vbox;};
}
);
};
};
};
This builds the new Guest Additions package, but does not use it in any way (nix-store --query --referrers /nix/store/NEW-VBOX-GUEST-ADDS-PATH shows no referrers); the "shipped" version is still used by both the systemd service as well as the environment packages.
Even providing the "overwrite" directly when selecting the boot.kernelPackages does not work:
boot.kernelPackages = pkgs.linuxPackages //
(
let vbox = pkgs.callPackage ./vbox-guest.nix { kernel = pkgs.linuxPackages.kernel; };
in
{
virtualboxGuestAdditions = vbox;
kernel = pkgs.linuxPackages.kernel // {virtualboxGuestAdditions = vbox;};
}
);
Putting the overwrite into ~/.nixpkgs/config.nix or /root/.nixpkgs/config.nix doesn't help either.
How can I change which package is used without manually "rewriting" the nixos module which provides this ...guest.enable setting?
I want to use hubstaff package from local nixpkgs repository,
let
# pass config so that packages use correct allowUnfree for example
nixpkgs-local = import /home/bjorn/projects/nixpkgs { inherit config; };
in
rec {
config.allowUnfree = true;
config.packageOverrides = old: {
# packages from local nixpkgs
inherit (nixpkgs-local) safeeyes hubstaff;
....
but its unfree package, so throws unfree package error
$ sudo nixos-rebuild dry-build
building the system configuration...
error: Package ‘hubstaff-1.3.1-ff75f26’ in /home/bjorn/projects/nixpkgs/pkgs/applications/misc/hubstaff/default.nix:60 has an unfree license (‘unfree’), refusing to evaluate.
As I understand I need to pass nixpkgs.config.allowUnfree = true, but import /home/bjorn/projects/nixpkgs { inherit config; }; above is not working
P.S.
other issue I have is that I have tried to peek what value I am passing in config.nixpkgs.allowUnfree here
{ config, pkgs, lib, ... }:
let r = {
imports = [
./hardware-configuration.nix
./hardware-configuration-override.nix
./hardware-programs.nix
/home/bjorn/projects/nixpkgs/nixos/modules/services/misc/safeeyes.nix
];
....
};
in
builtins.seq (lib.debug.showVal config.nixpkgs.allowUnfree) r
but I get infinite recursion error, maybe someone knows the way to do this?
To answer your second "P.S." question, here's the reason why and suggestions what to do instead.
The infinite recursion occurs because the module system needs to evaluate the 'root' of every module and some attributes like imports in order to build the term that represents the root of config.
With your call to seq you're evaluating an attribute of config at a point where config itself is still being evaluated.
Technically, you can solve this by adding your seq call to an attribute instead of around the entire module. This way, config can be evaluated without evaluating your seq call.
Probably an easier way to have a look at your configuration is to import it in nix repl
nix-repl> c = import <nixpkgs/nixos> { configuration = ./nixos/root/default.nix; /* or the file usually called configuration.nix */ }
nix-repl> c.config.nixpkgs.config.allowUnfree
true
You can use the :r command to reload all files when iterating. Nix likes to cache them because the implementation is geared toward batch execution.
Tnx to tilpner
I was passing wrong config
Namely,
this is config that import /home/bjorn/projects/nixpkgs was expecting
nix-repl> c = import <nixpkgs/nixos> {}
nix-repl> c.config.nixpkgs
{ config = { ... }; overlays = [ ... ]; pkgs = { ... }; system = "x86_64-linux"; }
This is what I was passing
nix-repl> c.config
{ _module = { ... }; assertions = [ ... ]; boot = { ... }; config = { ... }; containers = { ... }; dysnomia = { ... }; ec2 = { ... }; environment = { ... }; fileSystems = { ... }; fonts = { ... }; gnu = false; hardware = { ... }; i18n = { ... }; ids = { ... }; jobs = «error: The option `jobs' is used but not defined.»; kde = { ... }; krb5 = { ... }; lib = { ... }; meta = { ... }; nesting = { ... }; networking = { ... }; nix = { ... }; nixpkgs = { ... }; passthru = «error: The option `passthru' is used but not defined.»; power = { ... }; powerManagement = { ... }; programs = { ... }; security = { ... }; services = { ... }; sound = { ... }; swapDevices = [ ... ]; system = {
Its the one that passed to /etc/nixos/configuration.nix
Fix:
{ config, pkgs }:
let
# pass config so that packages use correct allowUnfree for example
unfreeConfig = config.nixpkgs.config // {
allowUnfree = true;
};
nixpkgs-local = import /home/bjorn/projects/nixpkgs { config = unfreeConfig; };
in
I created editor with Xtext 2.9.1 and now I want to make it independent of JDT. I followed this guide https://eclipse.org/Xtext/documentation/307_special_languages.html
but it does not seem to work. This is my ErrmsgUiModule.xtend
#FinalFieldsConstructor
class ErrmsgUiModule extends AbstractErrmsgUiModule {
override configure(Binder binder) {
super.configure(binder);
binder.bind(DefaultHighlightingConfiguration).to(ErrMsgHighlightingConfiguration);
binder.bind(DefaultSemanticHighlightingCalculator).to(ErrorSemanticHighlightingCalculator);
}
override bindIResourceForEditorInputFactory() {
return ResourceForIEditorInputFactory
}
override bindIResourceSetProvider() {
return SimpleResourceSetProvider
}
override provideIAllContainersState() {
return Access.getWorkspaceProjectsState()
}
}
I checked every overwritten method with debugger and all 3 methods are called. I did not created my own project wizard so this should be enough.
But still after plugin installating the Java project wizard becomes available...
/Edit:
To provide more information, this is project's mwe2 file
module com.xxx.lang.errmsg.GenerateErrmsg
import org.eclipse.xtext.xtext.generator.*
import org.eclipse.xtext.xtext.generator.model.project.*
import org.eclipse.xtext.ui.generator.*
var rootPath = ".."
Workflow {
component = XtextGenerator {
configuration = {
project = StandardProjectConfig {
baseName = "com.xxx.lang.errmsg"
rootPath = rootPath
runtimeTest = {
enabled = true
}
eclipsePlugin = {
enabled = true
}
eclipsePluginTest = {
enabled = true
}
createEclipseMetaData = true
}
code = {
encoding = "windows-1250"
fileHeader = "/*\n * generated by Xtext \${version}\n */"
}
}
language = StandardLanguage {
name = "com.xxx.lang.errmsg.Errmsg"
fileExtensions = "msg"
fragment = formatting.Formatter2Fragment2 auto-inject {}
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
}
}
}
and this is list of Dependencies from plugin.xml for various projects:
project com.xxx.lang.errmsg
org.eclipse.xtext,
org.eclipse.xtext.xbase,
org.eclipse.equinox.common;bundle-version="3.5.0",
org.eclipse.emf.ecore,
org.eclipse.xtext.xbase.lib,
org.antlr.runtime,
org.eclipse.xtext.util,
org.eclipse.xtend.lib,
org.eclipse.emf.common,
org.objectweb.asm;bundle-version="[5.0.1,6.0.0)";resolution:=optional,
org.eclipse.xtext.ui
project com.xxx.lang.errmsg.ui
com.xxx.lang.errmsg,
com.xxx.lang.errmsg.ide,
org.eclipse.xtext.ui,
org.eclipse.xtext.ui.shared,
org.eclipse.xtext.ui.codetemplates.ui,
org.eclipse.ui.editors;bundle-version="3.5.0",
org.eclipse.ui.ide;bundle-version="3.5.0",
org.eclipse.ui,
org.eclipse.compare,
org.eclipse.xtext.builder,
org.eclipse.xtend.lib;resolution:=optional,
org.eclipse.xtext.xbase.lib,
org.eclipse.xtext.xbase.ui
/Edit2: According to this topic https://bugs.eclipse.org/bugs/show_bug.cgi?id=336217, I also tried to disable all org.eclipse.jdt* plugins in run configuration. This is what i get http://pastebin.com/Wi0gzceM
You have to remove the dependencies on org.eclipse.xtext.xbase and org.eclipse.xtext.xbase.ui from your runtime and UI project.
Make sure if you open the Plug-in Dependencies in the Package Explorer that you do not see org.eclipse.jdt.core in the list. If so, there is another plug-in having a (transitive) dependency. Find out which and remove.
Using Delphi, how do I access the equivalent of .NET's System.Environment.SpecialFolder.LocalApplicationData variable (which works on any version of Windows)? I assumed I could just do:
dir := GetEnvironmentVariable('LOCALAPPDATA');
This works on Vista but XP doesn't seem to set that environment variable by default at least on my test machine.
In Delphi, the special system folder path constants are defined in ShlObj.DCU, and are referenced in the form of CSIDL_ followed by a symbolic name.
Example:
CSIDL_DESKTOPDIRECTORY returns the
path to the current desktop
CSIDL_PERSONAL is the My Documents directory
CSIDL___LOCAL_APPDATA is the (user name)\Local Settings\Application
Data directory
Here's a quick function that will return the appropriate special folder path when given the symbolic name. Make sure you include the SHLOBJ.DCU unit in your USES statement, and use the following:
function GetSpecialFolderPath(Folder: Integer; CanCreate: Boolean): string;
// Gets path of special system folders
//
// Call this routine as follows:
// GetSpecialFolderPath (CSIDL_PERSONAL, false)
// returns folder as result
//
var
FilePath: array [0..255] of char;
begin
SHGetSpecialFolderPath(0, #FilePath[0], FOLDER, CanCreate);
Result := FilePath;
end;
================================================================
For reference, the constants are as follows:
CSIDL_DESKTOP = $0000; { <desktop> }
CSIDL_INTERNET = $0001; { Internet Explorer (icon on desktop) }
CSIDL_PROGRAMS = $0002; { Start Menu\Programs }
CSIDL_CONTROLS = $0003; { My Computer\Control Panel }
CSIDL_PRINTERS = $0004; { My Computer\Printers }
CSIDL_PERSONAL = $0005; { My Documents. This is equivalent to CSIDL_MYDOCUMENTS in XP and above }
CSIDL_FAVORITES = $0006; { <user name>\Favorites }
CSIDL_STARTUP = $0007; { Start Menu\Programs\Startup }
CSIDL_RECENT = $0008; { <user name>\Recent }
CSIDL_SENDTO = $0009; { <user name>\SendTo }
CSIDL_BITBUCKET = $000a; { <desktop>\Recycle Bin }
CSIDL_STARTMENU = $000b; { <user name>\Start Menu }
CSIDL_MYDOCUMENTS = $000c; { logical "My Documents" desktop icon }
CSIDL_MYMUSIC = $000d; { "My Music" folder }
CSIDL_MYVIDEO = $000e; { "My Video" folder }
CSIDL_DESKTOPDIRECTORY = $0010; { <user name>\Desktop }
CSIDL_DRIVES = $0011; { My Computer }
CSIDL_NETWORK = $0012; { Network Neighborhood (My Network Places) }
CSIDL_NETHOOD = $0013; { <user name>\nethood }
CSIDL_FONTS = $0014; { windows\fonts }
CSIDL_TEMPLATES = $0015;
CSIDL_COMMON_STARTMENU = $0016; { All Users\Start Menu }
CSIDL_COMMON_PROGRAMS = $0017; { All Users\Start Menu\Programs }
CSIDL_COMMON_STARTUP = $0018; { All Users\Startup }
CSIDL_COMMON_DESKTOPDIRECTORY = $0019; { All Users\Desktop }
CSIDL_APPDATA = $001a; { <user name>\Application Data }
CSIDL_PRINTHOOD = $001b; { <user name>\PrintHood }
CSIDL_LOCAL_APPDATA = $001c; { <user name>\Local Settings\Application Data (non roaming) }
CSIDL_ALTSTARTUP = $001d; { non localized startup }
CSIDL_COMMON_ALTSTARTUP = $001e; { non localized common startup }
CSIDL_COMMON_FAVORITES = $001f;
CSIDL_INTERNET_CACHE = $0020;
CSIDL_COOKIES = $0021;
CSIDL_HISTORY = $0022;
CSIDL_COMMON_APPDATA = $0023; { All Users\Application Data }
CSIDL_WINDOWS = $0024; { GetWindowsDirectory() }
CSIDL_SYSTEM = $0025; { GetSystemDirectory() }
CSIDL_PROGRAM_FILES = $0026; { C:\Program Files }
CSIDL_MYPICTURES = $0027; { C:\Program Files\My Pictures }
CSIDL_PROFILE = $0028; { USERPROFILE }
CSIDL_SYSTEMX86 = $0029; { x86 system directory on RISC }
CSIDL_PROGRAM_FILESX86 = $002a; { x86 C:\Program Files on RISC }
CSIDL_PROGRAM_FILES_COMMON = $002b; { C:\Program Files\Common }
CSIDL_PROGRAM_FILES_COMMONX86 = $002c; { x86 C:\Program Files\Common on RISC }
CSIDL_COMMON_TEMPLATES = $002d; { All Users\Templates }
CSIDL_COMMON_DOCUMENTS = $002e; { All Users\Documents }
CSIDL_COMMON_ADMINTOOLS = $002f; { All Users\Start Menu\Programs\Administrative Tools }
CSIDL_ADMINTOOLS = $0030; { <user name>\Start Menu\Programs\Administrative Tools }
CSIDL_CONNECTIONS = $0031; { Network and Dial-up Connections }
CSIDL_COMMON_MUSIC = $0035; { All Users\My Music }
CSIDL_COMMON_PICTURES = $0036; { All Users\My Pictures }
CSIDL_COMMON_VIDEO = $0037; { All Users\My Video }
CSIDL_RESOURCES = $0038; { Resource Directory }
CSIDL_RESOURCES_LOCALIZED = $0039; { Localized Resource Directory }
CSIDL_COMMON_OEM_LINKS = $003a; { Links to All Users OEM specific apps }
CSIDL_CDBURN_AREA = $003b; { USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning }
CSIDL_COMPUTERSNEARME = $003d; { Computers Near Me (computered from Workgroup membership) }
CSIDL_PROFILES = $003e;
See this article.
Edit:
As added in the comment by stukelly there is a lot more information available about the SHGetFolderPath() functionality. The Delphi VCL really should have functionality for getting standard paths, and if Embarcadero is indeed going to have another Delphi-like tool on another OS this will be all the more important. For a multi-platform implementation of system standard paths see also the documentation of wxStandardPaths in wxWidgets. On MSW this uses the various CSIDL_XXX constants.
Assuming you can make WinAPI calls from Delphi (which ISTR you can), you used to be able to do that with an API call (something like GetSystemFolder or GetUserDataFolder). It's been a while since I've had to do that, but I think you can now do it with SHGetFolderPath, by passing in CSIDL_LOCAL_APPDATA.