We are writing a ADF application, and we are implementing internationalization. It looks like JavaVM doesn't recognize the Faroese locale (fa), and therefor uses the wrong date format.
Is there a way to override the locale specific date format in Oracle ADF?
Found it!
Added: <formatting-locale>da_DK</formatting-locale> to trinidad-config.xml
Related
I am trying to use Cypress.moment to compare dates. The targeted website is in french so the date format.
Therefore, I intended to use moment.js method to switch fr locale.
Cypress.moment.locale('fr')
I should be able to do that as they say on cypress documentation :
Cypress automatically includes moment.js and exposes it as Cypress.moment
https://docs.cypress.io/api/utilities/moment.html#Syntax
Then,
const todaysDate = Cypress.moment().format('Do')
const currentMonth = Cypress.moment().format('MMMM')
cy.get('.date__title').should('contain', todaysDate)
cy.get('.c-title').should('contain', currentMonth)
But the assertion fails as cypress refuse to take into account the fr locale. It keeps comparing 'décembre' with 'december' for instance. Which fails obviously.
I am doing something wrong ?
in the same aforementioned thread, a working answer recently surfaced:
put this in support/index.js:
Cypress.moment.locale('de');
it worked brilliantly in my project
Unfortunately, at the time of writing, I think this is not possible with Cypress.moment.locale(), as you can see in this issue in their git repository.
As commented there moment.locale requires an import in addition to the standard moment import, that import is moment-with-locales.min.js and has not been included in Cypress.
Im struggling with Stof Doctrine Extensions - Translatable for Symfony2. It works fine but I want for my default locale to get data from the original entity, not from the ext_translations. If I don't need it I don't want to make extra queries to get this translations.
Is this possible to achieve that and If yes how I can make it ?
Getting the data from the original entity for the default locale does not seem to me like a good practice to begin with, considering that you may want to be able to change the default locale later.
I'm using JMSI18nRoutingBundle for locale routing on our new site, but our existing site uses language + country in the following format and I need to keep the URLs looking the same.
example.com/us/en/hello (en_US)
example.com/be/fr/bonjour (fr_BE)
Is there any way to do this using config? If not, where is the best place to start customizing?
It doesn't look it's possible to do through config, but it can be done by replacing default implementation of PatternGenerationStrategyInterface by your own implementation.
You can check out default implementation that bundle uses here.
After you create your own implementation, just make bundle use your own implementation by setting the config parameter. If you're using YAML for example:
parameters:
jms_i18n_routing.pattern_generation_strategy.class: YourBundle\YourImplementationClass
Hint: you can basically copy/paste from default implementation and change line 69 to use str_replace('_', '/', $locale) instead of just $locale. That way, newly generated route pattern will contain a / if locale contains an _.
Not very elegant solution, but bundle unfortunately doesn't provide enough configuration to make it prettier.
Before I updated Rails, the default Time format the API was returning was yyyy-MM-dd'T'HH:mm:ss'Z'. Now it returns yyyy-MM-dd'T'HH:mm:ss:sss'Z'. I want to change it back due to apps that rely on the old time format. How can I change this PROJECT default format that Time::DateTime's to_s method returns?
Edit:
I should probably mention I started using the active_model_serializer gem. Not sure if that makes a difference. My guess is this change happened after the update from Rails 4.0.x to 4.1.x. Also I want to change this format for the project. This format changed between Rails versions. active_model_serializer uses to_s, so it makes more sense to override how to project sets this. I don't know where that is.
You can just use strftime:
Time.now.strftime("%Y-%M-%d %H:%m:%S%Z")
one of your gems is probably overriding the DateTime to_s method. you can just override it again with you own method back
Maybe you need this:
# config/initializers/time_with_zone.rb
module ActiveSupport
class TimeWithZone
def as_json(options = nil)
iso8601
end
end
end
You can augment the Ruby built-in Date::DATE_FORMATS and Time::DATE_FORMATS
DATE_FORMAT = "%m/%d/%Y".freeze
TIME_FORMAT = "#{DATE_FORMAT} %l:%M%P".freeze
format_defaults = {
default: DATE_FORMAT,
date_time12: TIME_FORMAT,
date_time24: "#{DATE_FORMAT} %H:%M",
}.freeze
Date::DATE_FORMATS.merge!(format_defaults)
Time::DATE_FORMATS.merge!(format_defaults)
I want to create a dynamic php date format. Example: show the time of the node if it was published today and only the day/month when older then today. I want this format to be available throughout Drupal like the other predefined date formats in Drupal (not just on theme level).
I found the (D7 only) hook for hook_date_format_types but even that one doesn't seem to allow for a callback where I could define this PHP logic.
Does anyone know which hook would make this possible? Or a module which does this?
In Drupal6, format_date() has the dates and times hardcoded. Also, format_date() does not allow callbacks, but it does allow a custom string. That is where you can apply a trick: instead of hardcoding the string in there, you call a function that returns a string.
function mydate_format($timestamp) {
$now = time();
if (($now - $timestamp) < (60*60*24)) {
return "H:i";
}
else {
return "d:m:Y";
}
}
print format_date($timestamp, 'custom', mydate_format($timestamp));
The second option is to re-define a date-timestamp, but that is both hackish and limited. Date-formats are defined with variable_get(), but don't pass the timestamp along; so your example of switching formats based on the value of timestamp is not possible this way.
In settings.php:
$conf['date_format_long'] = $conf['debug'] ? 'r' : 'l, F j, Y - H:i';
This will switch from one value to another, based on whether your settings.php has a flag "debug" set to TRUE or not. As mentioned: the use for this is limited, since you cannot get any context.
The third alternative is to use Date API which offers onlinle configurable time-formats. But that is both clumsy and insecure (inputting executable PHP in your database). It also depends on a very large module-set. And has the same downside as the first solution: you cannot use format_date, but must use a modified function call, instead of format_date(). See all the options at The Drupal.org date themeing handbook.
GOTCHA In all cases Drupal will not call this function for cached content. If you want to have the dates really dynamic you either need to avoid caching alltogether, or implement the date-formatting in clientside javascript.
TL;DR: You cannot have dynamic date-formats without changing some of the code on theme-level. Using a callback-function to generate the "custom" dateformat is the simplest, working solution.
You can use Date API module to add your custom date formatting. Date API module is inside the Date module. After enabling the Date API module you can go the path "admin/settings/date-time/formats/add" to add your custom format.
"admin/settings/date-time/formats/configure" is the path to configure date formats.
Have a look at these. Happy coding.
Thanks
RT
You can go to node.tpl.php(possibly in sites/all/themes/theme_name/node.tpl.php). Here yo can find $created variable, to reformat date you can use your custom function and change the $created as you want.After this all nodes will use your formatted dates.
Regatds,
Chintan.
Use the features module. Create a feature.
In the resulting feature module, on the [feature].module file, create a hook_nodeapi function and format the field with a conditional statement that takes into account the current date() for how the date will be displayed and feed it into the $node->content var.
And that is the way rockstars would do it (-;