Error: Attempting to inject an unknown injection: 'service:i18n' - ember.js

i have the following Problem with ember-i18n:
Error: Attempting to inject an unknown injection: 'service:i18n'
at Registry.validateInjections (ember.debug.js:2303)
at ember.debug.js:1538
at runInDebug (ember.debug.js:5813)
at Object.runInDebug (ember.debug.js:17396)
at instantiate (ember.debug.js:1532)
at lookup (ember.debug.js:1385)
at Container.lookup (ember.debug.js:1304)
at Class.lookup (ember.debug.js:32564)
at Class._internalGetHandler (router-ext.js:107)
at Class._getHandlerForEngine (router-ext.js:84)
I use the ember-i18n plugin in an ember engine. My i18n initializers addon/instance-initializers/i18n.js:
export default {
name: 'i18n',
initialize: function(applicationInstance) {
const i18nService = applicationInstance.lookup('service:i18n');
i18nService.set('defaultLocale', window.I18n.defaultLocale);
i18nService.set('locale', window.I18n.locale);
}
};
In my index route (routes/index.js) i have the following code:
import Ember from 'ember';
export default Ember.Route.extend({
i18n: Ember.inject.service(),
actions: {
didTransition() {
Ember.run.scheduleOnce('afterRender', this, function() {
console.log(this.get('i18n').t('error_empty_user_data'));
// ....
});
}
}
});
How can I declare the i18n service?
I use the ember-18n 4.5.0 Version and the 2.10.0 ember-cli Version.

The initializer should run after i18n one.
export default {
name: 'i18n',
after: ['ember-i18n'],
initialize: function(applicationInstance) {
const i18nService = applicationInstance.lookup('service:i18n');
i18nService.set('defaultLocale', window.I18n.defaultLocale);
i18nService.set('locale', window.I18n.locale);
}
};

Related

Is it possible to use androidx.appcompat.app.ActionBarDrawerToggle WITHOUT toobar

*android.useAndroidX=true
android.enableJetifier=true*
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('com.crashlytics.sdk.android:crashlytics:2.7.0#aar') { transitive = true; }
I migrate to androidx package.
All project is success build except this:
package android.support.v7.app does not exist
private ActionBarDrawerToggle mDrawerToggle;
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer, R.string.app_name, R.string.app_name)
in my activity:
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
public class MainNavigationDrawerFragmentActivity extends androidx.fragment.app.FragmentActivity {
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_navigation_drawer, R.string.app_name, R.string.app_name)
}
In new androidx.appcompat.app.ActionBarDrawerToggle I must use androidx.appcompat.widget.Toolbar.
But in my code I use action bar. So as result not compile.
The questions are:
Is it possible to use androidx.appcompat.app.ActionBarDrawerToggle WITHOUT toobar
Is it possible to use androidx.appcompat.app.ActionBarDrawerToggle WITH actionbar ?

UMD syntax with fallback global

My Setup
I'm compiling my .ts module 'FooModule' into an UMD module in Visual Studio 2015. I would like to extend this UMD syntax, so that the module will be injected into the global object as fallback when no module loading system is present, and I would like to automate this task as part of the build-process.
The UMD Syntax
When compiling a TypeScript module with the UMD syntax (Universal Module Definition syntax), modules that are compatible with both RequireJS and NodeJS are emitted:
foo-module.ts
export class Foo {
// ...
}
... is compiled into:
foo-module.js
(function (factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
} else if (typeof define === 'function' && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
var Foo = (function () {
function Foo() {
}
return Foo;
}());
exports.Foo = Foo;
});
Fallback to Global Inject
However, as part of the Universal part of UMD, I would like my module to be usable without any module loading system as well. My module has no dependencies.
This is usually done by adding a third case as a fallback for when neither the RequireJS nor the NodeJS module system are present, which will effectively inject into the global object. For foo-module, this would look like:
(function (global, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
} else if (typeof define === 'function' && define.amd) {
define(["require", "exports"], factory);
} else {
// *****************************
factory(null, global.FooModule || (global.FooModule = {})); // <- This part.
// *****************************
}
})(this, function (require, exports) {
"use strict";
var Foo = (function () {
function Foo() {
}
return Foo;
}());
// In browsers, this means 'window.FooModule.Foo = Foo'.
exports.Foo = Foo;
});
I believe this would suffice in all cases when there are no external dependencies (assuming no two modules with the same name have been loaded this way).
I understand I can just rewrite manually after each build, but how could I automate this task (or something with identical results) as part of a build-process in Visual Studio (2015)?
I understand I can just rewrite manually after each build, but how could I automate this task (or something with identical results) as part of a build-process in Visual Studio (2015)?
You will have to create this yourself.
More
There are a few variations of UMD : https://github.com/umdjs/umd the one you want is fallback browser global : https://github.com/umdjs/umd/blob/master/templates/returnExports.js
This is not the version in TypeScript because global is pretty much no module system.

C++ node.js Addons - Explanation of parameters in Init()

Can someone explain the difference between the one-argument form and the two-argument form of Init when creating a c++ node.js addon?
void Init(Local<Object> exports) {}
void Init(Local<Object> exports, Local<Object> module) {}
In general you could always use the second method template, but exports or module provide different options.
Using the following example:
void Init(Local<Object> exports) {
NODE_SET_METHOD(exports, "test", MyTest);
}
will add the function test as a "function property" on your exports object.
So you could use the following JS code and it would, for example, print it out to the stdout using the test function from your exports object:
const test = require('./path/to/node/addon/addon.node');
test.test('my message');
On the other hand:
void Init(Local<Object> exports, Local<Object> module) {
NODE_SET_METHOD(module, "exports", MyDummyCallback);
}
Provides you with the full module (module) and allows you to override your exports. You could call something like this from JS:
const test = require('./path/to/node/addon/addon.node');
test('test');
Will print your test message to the tty using the overridden module.

Is casting necessary in Typescript for this simple case?

Say I have a test.ts and a MY_MODULE.d.ts file:
MY_MODULE.d.ts:
module MY_MODULE
{
export class Config {
UserId : string;
};
export function Init( config : Config );
}
test.ts:
/// <reference path="MY_MODULE.d.ts" />
MY_MODULE.Init(<MY_MODULE.Config>{ UserId: 'Josh' });
My question: Is it possible to fix either the definition file or the .ts file so that the cast in the latter is unnecessary?
Use export interface Config instead of export class Config.
Typescript will infer the correct type based on the signature of the object, so the cast is not necessary.
Copying the code into the playground, a couple of compile errors were immediately picked up. Firstly, Init needs an implementation.
Secondly, the Config class does not have a constructor.
The following code compiles cleanly:
module MY_MODULE
{
export class Config {
UserId : string;
};
export function Init( config : Config ) {
}
}
var myConfig = new MY_MODULE.Config();
myConfig.UserId = 'Josh'
MY_MODULE.Init(myConfig);
It would be better to define a constructor for Config as follows:
module MY_MODULE
{
export class Config {
UserId : string;
constructor(userId : string) {
this.UserId = userId;
}
};
export function Init( config : Config ) {
}
}
MY_MODULE.Init(new MY_MODULE.Config('Josh'));

Export type into python

I want to export singleton into python using boost.python and use it there. Here is the code:
class ConfigManager : public boost::serialization::singleton<ConfigManager> {};
inline ConfigManager &configManager() { return ConfigManager::get_mutable_instance(); }
BOOST_PYTHON_MODULE(ConfigManager)
{
bp::class_<ConfigManager, boost::noncopyable>("ConfigManager", bp::no_init);
bp::def("getHandle", &configManager, bp::return_value_policy<bp::copy_non_const_reference>());
}
Now, when I call getHandle in python, I get:
TypeError: No to_python (by-value)
converter found for C++ type:
ConfigManager
What I did wrong?
copy_non_const_reference will try to copy your reference to a Python object, you should use instead bp::reference_existing_object, I tried here and the error message disappeared