Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[l10n] Add Danish (da-DK) locale #29485

Merged
merged 5 commits into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions dangerfile2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// inspire by reacts dangerfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbrookes has this file been added by accident?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears so

// danger has to be the first thing required!
const { danger, markdown } = require('danger');
const { exec } = require('child_process');
const { loadComparison } = require('./scripts/sizeSnapshot');

const azureBuildId = process.env.AZURE_BUILD_ID;
const azureBuildUrl = `https://dev.azure.com/mui-org/Material-UI/_build/results?buildId=${azureBuildId}`;
const dangerCommand = process.env.DANGER_COMMAND;

const parsedSizeChangeThreshold = 300;
const gzipSizeChangeThreshold = 100;

const UPSTREAM_REMOTE = 'danger-upstream';

/**
* This is mainly used for local development. It should be executed before the
* scripts exit to avoid adding internal remotes to the local machine. This is
* not an issue in CI.
*/
async function reportBundleSizeCleanup() {
await git(`remote remove ${UPSTREAM_REMOTE}`);
}

/**
* creates a callback for Object.entries(comparison).filter that excludes every
* entry that does not exceed the given threshold values for parsed and gzip size
* @param {number} parsedThreshold
* @param {number} gzipThreshold
*/
function createComparisonFilter(parsedThreshold, gzipThreshold) {
return (comparisonEntry) => {
const [, snapshot] = comparisonEntry;
return (
Math.abs(snapshot.parsed.absoluteDiff) >= parsedThreshold ||
Math.abs(snapshot.gzip.absoluteDiff) >= gzipThreshold
);
};
}

/**
* checks if the bundle is of a package e.b. `@mui/material` but not
* `@mui/material/Paper`
* @param {[string, any]} comparisonEntry
*/
function isPackageComparison(comparisonEntry) {
const [bundleKey] = comparisonEntry;
return /^@[\w-]+\/[\w-]+$/.test(bundleKey);
}

/**
* Generates a user-readable string from a percentage change
* @param {number} change
* @param {string} goodEmoji emoji on reduction
* @param {string} badEmoji emoji on increase
*/
function addPercent(change, goodEmoji = '', badEmoji = ':small_red_triangle:') {
const formatted = (change * 100).toFixed(2);
if (/^-|^0(?:\.0+)$/.test(formatted)) {
return `${formatted}% ${goodEmoji}`;
}
return `+${formatted}% ${badEmoji}`;
}

function generateEmphasizedChange([bundle, { parsed, gzip }]) {
// increase might be a bug fix which is a nice thing. reductions are always nice
const changeParsed = addPercent(parsed.relativeDiff, ':heart_eyes:', '');
const changeGzip = addPercent(gzip.relativeDiff, ':heart_eyes:', '');

return `**${bundle}**: parsed: ${changeParsed}, gzip: ${changeGzip}`;
}

/**
* Puts results in different buckets wh
* @param {*} results
*/
function sieveResults(results) {
const main = [];
const pages = [];

results.forEach((entry) => {
const [bundleId] = entry;

if (bundleId.startsWith('docs:')) {
pages.push(entry);
} else {
main.push(entry);
}
});

return { all: results, main, pages };
}

function prepareBundleSizeReport() {
markdown(
`Bundle size will be reported once [Azure build #${azureBuildId}](${azureBuildUrl}) finishes.`,
);
}

async function reportBundleSize() {
// Use git locally to grab the commit which represents the place
// where the branches differ
const upstreamRepo = danger.github.pr.base.repo.full_name;
const upstreamRef = danger.github.pr.base.ref;
try {
await git(`remote add ${UPSTREAM_REMOTE} https://github.com/${upstreamRepo}.git`);
} catch (err) {
// ignore if it already exist for local testing
}
await git(`fetch ${UPSTREAM_REMOTE}`);
const mergeBaseCommit = await git(`merge-base HEAD ${UPSTREAM_REMOTE}/${upstreamRef}`);

const detailedComparisonRoute = `/size-comparison?buildId=${azureBuildId}&baseRef=${danger.github.pr.base.ref}&baseCommit=${mergeBaseCommit}&prNumber=${danger.github.pr.number}`;
const detailedComparisonUrl = `https://mui-dashboard.netlify.app${detailedComparisonRoute}`;

const comparison = await loadComparison(mergeBaseCommit, upstreamRef);

const { all: allResults, main: mainResults } = sieveResults(Object.entries(comparison.bundles));
const anyResultsChanges = allResults.filter(createComparisonFilter(1, 1));

if (anyResultsChanges.length > 0) {
const importantChanges = mainResults
.filter(createComparisonFilter(parsedSizeChangeThreshold, gzipSizeChangeThreshold))
.filter(isPackageComparison)
.map(generateEmphasizedChange);

// have to guard against empty strings
if (importantChanges.length > 0) {
markdown(importantChanges.join('\n'));
}

const details = `[Details of bundle changes](${detailedComparisonUrl})`;

markdown(details);
} else {
markdown(`[No bundle size changes](${detailedComparisonUrl})`);
}
}

async function run() {
switch (dangerCommand) {
case 'prepareBundleSizeReport':
prepareBundleSizeReport();
break;
case 'reportBundleSize':
try {
await reportBundleSize();
} finally {
await reportBundleSizeCleanup();
}
break;
default:
throw new TypeError(`Unrecognized danger command '${dangerCommand}'`);
}
}

run().catch((error) => {
console.error(error);
process.exit(1);
});
114 changes: 63 additions & 51 deletions packages/mui-material/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,58 +545,70 @@ export const csCZ: Localization = {

export const daDK: Localization = {
components: {
MuiBreadcrumbs: { defaultProps: {
expandText: 'Vis sti',
}},
MuiTablePagination: { defaultProps: {
getItemAriaLabel: (type) => {
if (type === 'first') {
return 'Gå til den første side';
}
if (type === 'last') {
return 'Gå til den sidste side';
}
if (type === 'next') {
return 'Gå til den næste side';
}
// if (type === 'previous') {
return 'Gå til den forrige side';
MuiBreadcrumbs: {
defaultProps: {
expandText: 'Vis sti',
},
labelRowsPerPage: 'Rækker pr side:',
labelDisplayedRows: ({ from, to, count }) =>
`${from}-${to} af ${count !== -1 ? count : `mere end ${to}`}`,
}},
MuiRating: { defaultProps: {
getLabelText: value => `${value} Stjern${value !== 1 ? 'er' : ''}`,
emptyLabelText: 'Tom',
}},
MuiAutocomplete: { defaultProps: {
clearText: 'Slet',
closeText: 'Luk',
loadingText: 'Indlæser…',
noOptionsText: 'Ingen muligheder',
openText: 'Åben',
}},
MuiAlert: { defaultProps: {
closeText: 'Luk',
}},
MuiPagination: { defaultProps: {
'aria-label': 'Sideinddelings navigation',
getItemAriaLabel: (type, page, selected) => {
if (type === 'page') {
return `${selected ? '' : 'Go to '}page ${page}`;
}
if (type === 'first') {
return 'Gå til den første side';
}
if (type === 'last') {
return 'Gå til den sidste side';
}
if (type === 'next') {
return 'Gå til den næste side';
}
// if (type === 'previous') {
return 'Gå til den forrige side';
},
MuiTablePagination: {
defaultProps: {
getItemAriaLabel: (type) => {
if (type === 'first') {
return 'Gå til den første side';
}
if (type === 'last') {
return 'Gå til den sidste side';
}
if (type === 'next') {
return 'Gå til den næste side';
}
// if (type === 'previous') {
return 'Gå til den forrige side';
},
labelRowsPerPage: 'Rækker pr side:',
labelDisplayedRows: ({ from, to, count }) =>
`${from}-${to} af ${count !== -1 ? count : `mere end ${to}`}`,
},
},
MuiRating: {
defaultProps: {
getLabelText: (value) => `${value} Stjern${value !== 1 ? 'er' : ''}`,
emptyLabelText: 'Tom',
},
},
MuiAutocomplete: {
defaultProps: {
clearText: 'Slet',
closeText: 'Luk',
loadingText: 'Indlæser…',
noOptionsText: 'Ingen muligheder',
openText: 'Åben',
},
},
MuiAlert: {
defaultProps: {
closeText: 'Luk',
},
},
MuiPagination: {
defaultProps: {
'aria-label': 'Sideinddelings navigation',
getItemAriaLabel: (type, page, selected) => {
if (type === 'page') {
return `${selected ? '' : 'Go to '}page ${page}`;
}
if (type === 'first') {
return 'Gå til den første side';
}
if (type === 'last') {
return 'Gå til den sidste side';
}
if (type === 'next') {
return 'Gå til den næste side';
}
// if (type === 'previous') {
return 'Gå til den forrige side';
},
},
},
},
Expand Down